/root/doris/be/src/http/http_request.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <glog/logging.h> |
21 | | |
22 | | #include <map> |
23 | | #include <memory> |
24 | | #include <string> |
25 | | |
26 | | #include "http/http_method.h" |
27 | | #include "util/string_util.h" |
28 | | |
29 | | struct evhttp_request; |
30 | | |
31 | | namespace doris { |
32 | | |
33 | | class HttpHandler; |
34 | | |
35 | | class HttpRequest { |
36 | | public: |
37 | | HttpRequest(evhttp_request* ev_req); |
38 | | |
39 | | ~HttpRequest(); |
40 | | |
41 | | int init_from_evhttp(); |
42 | | |
43 | 54 | HttpMethod method() const { return _method; } |
44 | | |
45 | | // path + '?' + query |
46 | 0 | const std::string& uri() const { return _uri; } |
47 | | |
48 | | // return raw path without query string after '?' |
49 | 47 | const std::string& raw_path() const { return _raw_path; } |
50 | | |
51 | | const std::string& header(const std::string& key) const; |
52 | | |
53 | | const std::string& param(const std::string& key) const; |
54 | | |
55 | | // return params |
56 | 0 | const StringCaseUnorderedMap<std::string>& headers() { return _headers; } |
57 | | |
58 | | // return params |
59 | 53 | std::map<std::string, std::string>* params() { return &_params; } |
60 | | |
61 | 0 | const std::map<std::string, std::string>& query_params() const { return _query_params; } |
62 | | |
63 | | std::string get_request_body(); |
64 | | |
65 | | void add_output_header(const char* key, const char* value); |
66 | | |
67 | | std::string debug_string() const; |
68 | | |
69 | 46 | void set_handler(HttpHandler* handler) { _handler = handler; } |
70 | 24 | HttpHandler* handler() const { return _handler; } |
71 | | |
72 | 49 | struct evhttp_request* get_evhttp_request() const { return _ev_req; } |
73 | | |
74 | 0 | std::shared_ptr<void> handler_ctx() const { return _handler_ctx; } |
75 | 0 | void set_handler_ctx(std::shared_ptr<void> ctx) { |
76 | 0 | DCHECK(_handler != nullptr); |
77 | 0 | _handler_ctx = ctx; |
78 | 0 | } |
79 | | |
80 | | const char* remote_host() const; |
81 | | |
82 | | private: |
83 | | HttpMethod _method; |
84 | | std::string _uri; |
85 | | std::string _raw_path; |
86 | | |
87 | | StringCaseUnorderedMap<std::string> _headers; |
88 | | std::map<std::string, std::string> _params; |
89 | | std::map<std::string, std::string> _query_params; |
90 | | |
91 | | struct evhttp_request* _ev_req = nullptr; |
92 | | HttpHandler* _handler = nullptr; |
93 | | |
94 | | std::shared_ptr<void> _handler_ctx; |
95 | | std::string _request_body; |
96 | | }; |
97 | | |
98 | | } // namespace doris |