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/exceptions.hpp>
17#include <userver/server/handlers/formatted_error_data.hpp>
18#include <userver/server/handlers/handler_base.hpp>
19#include <userver/server/http/http_request.hpp>
20#include <userver/server/http/http_response.hpp>
21#include <userver/server/http/http_response_body_stream_fwd.hpp>
22#include <userver/server/request/request_base.hpp>
24#include <userver/tracing/span.hpp>
26USERVER_NAMESPACE_BEGIN
35namespace server::handlers {
37class HttpHandlerStatistics;
38class HttpRequestStatistics;
39class HttpHandlerMethodStatistics;
40class HttpHandlerStatisticsScope;
70 const components::ComponentContext& component_context,
71 bool is_monitor =
false
74 ~HttpHandlerBase() override;
80 virtual const std::string& HandlerName()
const;
82 const std::vector<http::HttpMethod>& GetAllowedMethods()
const;
86 HttpHandlerStatistics& GetHandlerStatistics()
const;
89 HttpRequestStatistics& GetRequestStatistics()
const;
98 std::string GetResponseDataForLoggingChecked(
99 const http::HttpRequest& request,
100 request::RequestContext& context,
101 const std::string& response_data
118 static yaml_config::Schema GetStaticConfigSchema();
121 [[
noreturn]]
void ThrowUnsupportedHttpMethod(
const http::HttpRequest& request)
const;
150 virtual bool IsStreamed()
const {
return is_body_streamed_; }
162 const http::HttpRequest& request,
163 request::RequestContext& context,
164 const std::string& request_body
169 const http::HttpRequest& request,
170 request::RequestContext& context,
171 const std::string& response_data
178 virtual std::string GetMetaType(
const http::HttpRequest&)
const;
184 void HandleHttpRequest(
http::HttpRequest& request,
request::RequestContext& context)
const;
186 void HandleRequestStream(
const http::HttpRequest& http_request,
request::RequestContext& context)
const;
188 std::string GetRequestBodyForLoggingChecked(
189 const http::HttpRequest& request,
190 request::RequestContext& context,
191 const std::string& request_body
194 template <
typename HttpStatistics>
195 void FormatStatistics(utils::statistics::Writer result,
const HttpStatistics& stats);
197 void SetResponseServerHostname(
http::HttpResponse& response)
const;
199 void BuildMiddlewarePipeline(
const components::ComponentConfig&,
const components::ComponentContext&);
201 const dynamic_config::Source config_source_;
202 const std::vector<http::HttpMethod> allowed_methods_;
203 const std::string handler_name_;
204 utils::statistics::Entry statistics_holder_;
206 std::unordered_map<
int, logging::Level> log_level_for_status_codes_;
208 std::unique_ptr<HttpHandlerStatistics> handler_statistics_;
209 std::unique_ptr<HttpRequestStatistics> request_statistics_;
211 bool set_response_server_hostname_;
212 bool is_body_streamed_;
214 std::unique_ptr<middlewares::HttpMiddlewareBase> first_middleware_;