Coverage Report

Created: 2026-01-11 02:49

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 <future>
23
#include <map>
24
#include <memory>
25
#include <string>
26
27
#include "common/config.h"
28
#include "http/http_method.h"
29
#include "util/string_util.h"
30
31
struct evhttp_request;
32
33
namespace doris {
34
35
class HttpHandler;
36
37
enum SendReplyType { REPLY_SYNC = 0, REPLY_ASYNC = 1 };
38
39
class HttpRequest {
40
public:
41
    HttpRequest(evhttp_request* ev_req);
42
43
    ~HttpRequest();
44
45
    int init_from_evhttp();
46
47
64
    HttpMethod method() const { return _method; }
48
49
    // path + '?' + query
50
0
    const std::string& uri() const { return _uri; }
51
52
    // return raw path without query string after '?'
53
54
    const std::string& raw_path() const { return _raw_path; }
54
55
    const std::string& header(const std::string& key) const;
56
57
    const std::string& param(const std::string& key) const;
58
59
    // return params
60
0
    const StringCaseUnorderedMap<std::string>& headers() { return _headers; }
61
62
    std::string get_all_headers() const;
63
64
    // return params
65
60
    std::map<std::string, std::string>* params() { return &_params; }
66
67
0
    const std::map<std::string, std::string>& query_params() const { return _query_params; }
68
69
    std::string get_request_body();
70
71
    void add_output_header(const char* key, const char* value);
72
73
    std::string debug_string() const;
74
75
53
    void set_handler(HttpHandler* handler) { _handler = handler; }
76
31
    HttpHandler* handler() const { return _handler; }
77
78
67
    struct evhttp_request* get_evhttp_request() const { return _ev_req; }
79
80
0
    std::shared_ptr<void> handler_ctx() const { return _handler_ctx; }
81
0
    void set_handler_ctx(std::shared_ptr<void> ctx) {
82
0
        DCHECK(_handler != nullptr);
83
0
        _handler_ctx = ctx;
84
0
    }
85
86
    const char* remote_host() const;
87
88
0
    void mark_send_reply(SendReplyType type = REPLY_ASYNC) { _send_reply_type = type; }
89
90
    void finish_send_reply();
91
    void wait_finish_send_reply();
92
93
private:
94
    SendReplyType _send_reply_type = REPLY_SYNC;
95
    HttpMethod _method;
96
    std::string _uri;
97
    std::string _raw_path;
98
99
    StringCaseUnorderedMap<std::string> _headers;
100
    std::map<std::string, std::string> _params;
101
    std::map<std::string, std::string> _query_params;
102
103
    struct evhttp_request* _ev_req = nullptr;
104
    HttpHandler* _handler = nullptr;
105
106
    std::shared_ptr<void> _handler_ctx;
107
    std::string _request_body;
108
109
    // ensure send_reply finished
110
    std::promise<bool> _http_reply_promise;
111
    std::future<bool> _http_reply_future = _http_reply_promise.get_future();
112
};
113
114
} // namespace doris