8#include <unordered_set>
11#include <userver/dynamic_config/source.hpp>
12#include <userver/logging/level.hpp>
13#include <userver/utils/statistics/entry.hpp>
14#include <userver/utils/token_bucket.hpp>
16#include <userver/server/handlers/auth/auth_checker_base.hpp>
17#include <userver/server/handlers/exceptions.hpp>
18#include <userver/server/handlers/formatted_error_data.hpp>
19#include <userver/server/handlers/handler_base.hpp>
20#include <userver/server/http/http_request.hpp>
21#include <userver/server/http/http_response.hpp>
22#include <userver/server/http/http_response_body_stream_fwd.hpp>
23#include <userver/server/request/request_base.hpp>
24#include <userver/tracing/span.hpp>
26USERVER_NAMESPACE_BEGIN
33namespace server::handlers {
35class HttpHandlerStatistics;
36class HttpRequestStatistics;
37class HttpHandlerMethodStatistics;
38class HttpHandlerStatisticsScope;
64 HttpHandlerBase(
const components::ComponentConfig& config,
65 const components::ComponentContext& component_context,
66 bool is_monitor =
false);
68 ~HttpHandlerBase()
override;
71 request::RequestContext& context)
const override;
75 virtual const std::string& HandlerName()
const;
77 const std::vector<http::HttpMethod>& GetAllowedMethods()
const;
81 HttpHandlerStatistics& GetHandlerStatistics()
const;
84 HttpRequestStatistics& GetRequestStatistics()
const;
95 std::string GetResponseDataForLoggingChecked(
96 const http::HttpRequest& request,
request::RequestContext& context,
97 const std::string& response_data)
const;
102 [[
noreturn]]
void ThrowUnsupportedHttpMethod(
103 const http::HttpRequest& request)
const;
110 const http::HttpRequest& request,
request::RequestContext& context)
const;
112 virtual void OnRequestCompleteThrow(
113 const http::HttpRequest& ,
114 request::RequestContext& )
const {}
128 server::
request::RequestContext&,
129 server::http::ResponseBodyStream&)
const;
137 virtual bool IsStreamed()
const {
return is_body_streamed_; }
149 const http::HttpRequest& request,
request::RequestContext& context,
150 const std::string& request_body)
const;
154 const http::HttpRequest& request,
request::RequestContext& context,
155 const std::string& response_data)
const;
160 request::RequestContext&)
const {}
162 virtual std::string GetMetaType(
const http::HttpRequest&)
const;
165 void HandleRequestStream(
const http::HttpRequest& http_request,
166 request::RequestContext& context)
const;
168 std::string GetRequestBodyForLoggingChecked(
169 const http::HttpRequest& request,
request::RequestContext& context,
170 const std::string& request_body)
const;
172 tracing::Span MakeSpan(
const http::HttpRequest& http_request,
173 const std::string& meta_type)
const;
175 void CheckAuth(
const http::HttpRequest& http_request,
176 request::RequestContext& context,
177 const dynamic_config::Snapshot& initial_config)
const;
179 void CheckRatelimit(
const http::HttpRequest& http_request)
const;
181 void DecompressRequestBody(http::HttpRequest& http_request)
const;
183 template <
typename HttpStatistics>
184 void FormatStatistics(
utils::statistics::Writer result,
185 const HttpStatistics& stats);
187 void SetResponseAcceptEncoding(http::HttpResponse& response)
const;
188 void SetResponseServerHostname(http::HttpResponse& response)
const;
190 const dynamic_config::Source config_source_;
191 const std::vector<http::HttpMethod> allowed_methods_;
192 const std::string handler_name_;
193 utils::statistics::Entry statistics_holder_;
195 std::unordered_map<
int, logging::Level> log_level_for_status_codes_;
197 std::unique_ptr<HttpHandlerStatistics> handler_statistics_;
198 std::unique_ptr<HttpRequestStatistics> request_statistics_;
199 std::vector<auth::AuthCheckerBasePtr> auth_checkers_;
202 bool set_response_server_hostname_;
203 mutable utils::TokenBucket rate_limit_;
204 bool is_body_streamed_;