10#include <userver/engine/task/task_processor_fwd.hpp>
12#include <userver/engine/io/sockaddr.hpp>
13#include <userver/server/http/form_data_arg.hpp>
14#include <userver/server/http/http_method.hpp>
15#include <userver/server/http/http_response.hpp>
16#include <userver/utils/datetime/wall_coarse_clock.hpp>
17#include <userver/utils/impl/internal_tag.hpp>
18#include <userver/utils/impl/transparent_hash.hpp>
19#include <userver/utils/str_icase.hpp>
21USERVER_NAMESPACE_BEGIN
23namespace server::handlers {
24class HttpRequestStatistics;
34class HttpRequest
final {
36 using HeadersMap = USERVER_NAMESPACE::
http::
headers::HeaderMap;
38 using HeadersMapKeys =
decltype(utils::impl::MakeKeysView(HeadersMap()));
40 using CookiesMap = std::unordered_map<std::string, std::string, utils::StrCaseHash>;
42 using CookiesMapKeys =
decltype(utils::impl::MakeKeysView(CookiesMap()));
45 explicit HttpRequest(
request::ResponseDataAccounter& data_accounter,
utils::impl::InternalTag);
48 HttpRequest(HttpRequest&&) =
delete;
49 HttpRequest(
const HttpRequest&) =
delete;
72 std::chrono::duration<
double> GetRequestTime()
const;
74 std::chrono::duration<
double> GetResponseTime()
const;
91 const std::string&
GetArg(std::string_view arg_name)
const;
110 bool HasArg(std::string_view arg_name)
const;
144 const std::string&
GetPathArg(std::string_view arg_name)
const;
163 const std::string&
GetHeader(std::string_view header_name)
const;
192 const std::string&
GetCookie(
const std::string& cookie_name)
const;
214 void SetRequestBody(std::string body);
215 void ParseArgsFromBody();
216 bool IsFinal()
const;
229 HttpResponse& GetHttpResponse()
const;
235 void MarkAsInternalServerError()
const;
237 void SetStartSendResponseTime();
238 void SetFinishSendResponseTime();
240 void WriteAccessLogs(
241 const logging::LoggerPtr& logger_access,
242 const logging::LoggerPtr& logger_access_tskv,
243 const std::string& remote_address
247 const logging::LoggerPtr& logger_access,
249 const std::string& remote_address
252 void WriteAccessTskvLog(
253 const logging::LoggerPtr& logger_access_tskv,
255 const std::string& remote_address
258 using UpgradeCallback = std::function<
void(std::unique_ptr<engine::io::RwBase>&&, engine::
io::Sockaddr&&)>;
260 bool IsUpgradeWebsocket()
const;
261 void SetUpgradeWebsocket(UpgradeCallback cb)
const;
262 void DoUpgrade(std::unique_ptr<engine::io::RwBase>&& socket, engine::
io::Sockaddr&& peer_name)
const;
266 void AccountResponseTime();
268 void SetPathArgs(std::vector<std::pair<std::string, std::string>> args);
273 void SetTaskProcessor(engine::TaskProcessor& task_processor);
274 engine::TaskProcessor* GetTaskProcessor()
const;
276 void SetHttpHandlerStatistics(handlers::HttpRequestStatistics&);
279 void SetResponseStreamId(std::int32_t);
280 void SetStreamProducer(impl::Http2StreamEventProducer&& producer);
282 void SetTaskCreateTime();
283 void SetTaskStartTime();
284 void SetResponseNotifyTime();
285 void SetResponseNotifyTime(std::chrono::steady_clock::time_point now);
287 friend class HttpRequestBuilder;
288 friend class HttpRequestHandler;
291 utils::FastPimpl<Impl, 1648, 16> pimpl_;