userver: userver/server/request/request_base.hpp Source File
Loading...
Searching...
No Matches
request_base.hpp
1#pragma once
2
3#include <chrono>
4#include <memory>
5#include <string>
6#include <vector>
7
8// TODO: use fwd declarations
9#include <userver/logging/fwd.hpp>
10#include <userver/server/request/response_base.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace engine::io {
15class Socket;
16class Sockaddr;
17} // namespace engine::io
18
19namespace server::request {
20
21class RequestBase {
22public:
23 RequestBase();
24 virtual ~RequestBase();
25
26 virtual bool IsFinal() const = 0;
27 virtual bool IsUpgradeWebsocket() const = 0;
28 virtual void DoUpgrade(std::unique_ptr<engine::io::RwBase>&& socket, engine::io::Sockaddr&& peer_name) const = 0;
29
30 virtual ResponseBase& GetResponse() const = 0;
31
32 virtual void WriteAccessLogs(
33 const logging::LoggerPtr& logger_access,
34 const logging::LoggerPtr& logger_access_tskv,
35 const std::string& remote_address
36 ) const = 0;
37
38 virtual const std::string& GetRequestPath() const = 0;
39
40 void SetTaskCreateTime();
41 void SetTaskStartTime();
42 void SetResponseNotifyTime();
43 void SetResponseNotifyTime(std::chrono::steady_clock::time_point now);
44 void SetStartSendResponseTime();
45 void SetFinishSendResponseTime();
46
47 virtual void SetMatchedPathLength(size_t length) = 0;
48
49 std::chrono::steady_clock::time_point StartTime() const { return start_time_; }
50
51 virtual void MarkAsInternalServerError() const = 0;
52
53 virtual void AccountResponseTime() = 0;
54
55protected:
56 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
57 std::chrono::steady_clock::time_point start_time_;
58 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
59 std::chrono::steady_clock::time_point task_create_time_;
60 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
61 std::chrono::steady_clock::time_point task_start_time_;
62 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
63 std::chrono::steady_clock::time_point response_notify_time_;
64 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
65 std::chrono::steady_clock::time_point start_send_response_time_;
66 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
67 std::chrono::steady_clock::time_point finish_send_response_time_;
68};
69
70} // namespace server::request
71
72USERVER_NAMESPACE_END