Coverage Report

Created: 2025-09-05 19:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/http/http_request.h
Line
Count
Source
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
64
    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
54
    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
    std::string get_all_headers() const;
59
60
    // return params
61
60
    std::map<std::string, std::string>* params() { return &_params; }
62
63
0
    const std::map<std::string, std::string>& query_params() const { return _query_params; }
64
65
    std::string get_request_body();
66
67
    void add_output_header(const char* key, const char* value);
68
69
    std::string debug_string() const;
70
71
53
    void set_handler(HttpHandler* handler) { _handler = handler; }
72
31
    HttpHandler* handler() const { return _handler; }
73
74
67
    struct evhttp_request* get_evhttp_request() const { return _ev_req; }
75
76
0
    std::shared_ptr<void> handler_ctx() const { return _handler_ctx; }
77
0
    void set_handler_ctx(std::shared_ptr<void> ctx) {
78
        DCHECK(_handler != nullptr);
79
0
        _handler_ctx = ctx;
80
0
    }
81
82
    const char* remote_host() const;
83
84
private:
85
    HttpMethod _method;
86
    std::string _uri;
87
    std::string _raw_path;
88
89
    StringCaseUnorderedMap<std::string> _headers;
90
    std::map<std::string, std::string> _params;
91
    std::map<std::string, std::string> _query_params;
92
93
    struct evhttp_request* _ev_req = nullptr;
94
    HttpHandler* _handler = nullptr;
95
96
    std::shared_ptr<void> _handler_ctx;
97
    std::string _request_body;
98
};
99
100
} // namespace doris