9#include <unordered_set>
12#include <userver/dynamic_config/source.hpp>
13#include <userver/logging/level.hpp>
14#include <userver/utils/statistics/entry.hpp>
15#include <userver/utils/token_bucket.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>
25#include <userver/tracing/span.hpp>
27USERVER_NAMESPACE_BEGIN
29namespace server::middlewares {
36namespace server::handlers {
38class HttpHandlerStatistics;
39class HttpRequestStatistics;
40class HttpHandlerMethodStatistics;
41class HttpHandlerStatisticsScope;
68 HttpHandlerBase(
const components::ComponentConfig& config,
69 const components::ComponentContext& component_context,
70 bool is_monitor =
false);
72 ~HttpHandlerBase()
override;
75 request::RequestContext& context)
const override;
79 virtual const std::string& HandlerName()
const;
81 const std::vector<http::HttpMethod>& GetAllowedMethods()
const;
85 HttpHandlerStatistics& GetHandlerStatistics()
const;
88 HttpRequestStatistics& GetRequestStatistics()
const;
99 std::string GetResponseDataForLoggingChecked(
100 const http::HttpRequest& request,
request::RequestContext& context,
101 const std::string& response_data)
const;
111 const std::exception& ex)
const;
119 static yaml_config::Schema GetStaticConfigSchema();
122 [[
noreturn]]
void ThrowUnsupportedHttpMethod(
123 const http::HttpRequest& request)
const;
130 const http::HttpRequest& request,
request::RequestContext& context)
const;
132 virtual void OnRequestCompleteThrow(
133 const http::HttpRequest& ,
134 request::RequestContext& )
const {}
148 server::
request::RequestContext&,
149 server::http::ResponseBodyStream&)
const;
157 virtual bool IsStreamed()
const {
return is_body_streamed_; }
169 const http::HttpRequest& request,
request::RequestContext& context,
170 const std::string& request_body)
const;
174 const http::HttpRequest& request,
request::RequestContext& context,
175 const std::string& response_data)
const;
180 request::RequestContext&)
const {}
182 virtual std::string GetMetaType(
const http::HttpRequest&)
const;
185 friend class middlewares::HandlerAdapter;
186 friend class middlewares::Auth;
188 void HandleHttpRequest(http::HttpRequest& request,
189 request::RequestContext& context)
const;
191 void HandleRequestStream(
const http::HttpRequest& http_request,
192 request::RequestContext& context)
const;
194 std::string GetRequestBodyForLoggingChecked(
195 const http::HttpRequest& request,
request::RequestContext& context,
196 const std::string& request_body)
const;
198 template <
typename HttpStatistics>
199 void FormatStatistics(utils::statistics::Writer result,
200 const HttpStatistics& stats);
202 void SetResponseServerHostname(http::HttpResponse& response)
const;
204 void BuildMiddlewarePipeline(
const components::ComponentConfig&,
207 const dynamic_config::Source config_source_;
208 const std::vector<http::HttpMethod> allowed_methods_;
209 const std::string handler_name_;
210 utils::statistics::Entry statistics_holder_;
212 std::unordered_map<
int, logging::Level> log_level_for_status_codes_;
214 std::unique_ptr<HttpHandlerStatistics> handler_statistics_;
215 std::unique_ptr<HttpRequestStatistics> request_statistics_;
217 bool set_response_server_hostname_;
218 bool is_body_streamed_;
220 std::unique_ptr<middlewares::HttpMiddlewareBase> first_middleware_;