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 {
22 public:
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,
29 engine::io::Sockaddr&& peer_name) const = 0;
30
31 virtual ResponseBase& GetResponse() const = 0;
32
33 virtual void WriteAccessLogs(const logging::LoggerPtr& logger_access,
34 const logging::LoggerPtr& logger_access_tskv,
35 const std::string& remote_address) const = 0;
36
37 virtual const std::string& GetRequestPath() const = 0;
38
39 void SetTaskCreateTime();
40 void SetTaskStartTime();
41 void SetResponseNotifyTime();
42 void SetResponseNotifyTime(std::chrono::steady_clock::time_point now);
43 void SetStartSendResponseTime();
44 void SetFinishSendResponseTime();
45
46 virtual void SetMatchedPathLength(size_t length) = 0;
47
48 std::chrono::steady_clock::time_point StartTime() const {
49 return start_time_;
50 }
51
52 virtual void MarkAsInternalServerError() const = 0;
53
54 virtual void AccountResponseTime() = 0;
55
56 protected:
57 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
58 std::chrono::steady_clock::time_point start_time_;
59 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
60 std::chrono::steady_clock::time_point task_create_time_;
61 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
62 std::chrono::steady_clock::time_point task_start_time_;
63 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
64 std::chrono::steady_clock::time_point response_notify_time_;
65 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
66 std::chrono::steady_clock::time_point start_send_response_time_;
67 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
68 std::chrono::steady_clock::time_point finish_send_response_time_;
69};
70
71} // namespace server::request
72
73USERVER_NAMESPACE_END