#include <userver/server/handlers/http_handler_base.hpp >
Base class for all the Userver HTTP Handlers .
Static options:
Inherits all the options from server::handlers::HandlerBase and adds the following ones:
Name Description Default value
log-level overrides log level for this handle <no override>
status-codes-log-level map of "status": log_level items to override span log level for specific status codes {}
middleware-pipeline-builder name of a component to build a middleware pipeline for this particular handler default-handler-middleware-pipeline-builder
Example usage:
namespace samples::hello {
public :
static constexpr std::string_view kName = "handler-hello-sample" ;
using HttpHandlerBase::HttpHandlerBase;
std::string HandleRequestThrow(
return "Hello world!\n" ;
}
};
}
Examples postgresql/functional_tests/basic_chaos/postgres_service.cpp , samples/grpc_service/grpc_service.cpp , samples/hello_service/hello_service.cpp , samples/http_caching/http_caching.cpp , samples/mongo_service/mongo_service.cpp , samples/multipart_service/service.cpp , samples/postgres_auth/postgres_service.cpp , samples/postgres_service/postgres_service.cpp , and samples/redis_service/redis_service.cpp .
Definition at line 66 of file http_handler_base.hpp .
HttpHandlerBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false)
void HandleRequest (request::RequestBase &request, request::RequestContext &context) const override
void ReportMalformedRequest (request::RequestBase &request) const final
virtual const std::string & HandlerName () const
const std::vector< http::HttpMethod > & GetAllowedMethods () const
virtual logging::Level GetLogLevelForResponseStatus (http::HttpStatus status) const
virtual FormattedErrorData GetFormattedExternalErrorBody (const CustomHandlerException &exc) const
std::string GetResponseDataForLoggingChecked (const http::HttpRequest &request, request::RequestContext &context, const std::string &response_data) const
void HandleCustomHandlerException (const http::HttpRequest &request, const CustomHandlerException &ex) const
void HandleUnknownException (const http::HttpRequest &request, const std::exception &ex) const
void LogUnknownException (const std::exception &ex) const
Helper function to log an unknown exception.
const std::optional< logging::Level > & GetLogLevel () const
Returns the default log level for the handler.
Public Member Functions inherited from server::handlers::HandlerBase
HandlerBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false)
bool IsMonitor () const
Returns whether this is a monitoring handler.
const HandlerConfig & GetConfig () const
Returns handler config.
LoggableComponentBase (const ComponentConfig &, const ComponentContext &)
LoggableComponentBase (LoggableComponentBase &&)=delete
LoggableComponentBase (const LoggableComponentBase &)=delete
~LoggableComponentBase () override=default
ComponentHealth GetComponentHealth () const override
void OnLoadingCancelled () override
void OnAllComponentsLoaded () override
void OnAllComponentsAreStopping () override
◆ GetLogLevelForResponseStatus()
Override it if you need a custom logging level for messages about finish of request handling for some http statuses.
◆ GetRequestBodyForLogging()
◆ GetResponseDataForLogging()
◆ HandleCustomHandlerException()
Takes the exception and formats it into response, as specified by exception.
◆ HandleRequest()
◆ HandleRequestThrow()
The core method for HTTP request handling. request
arg contains HTTP headers, full body, etc. The method should return response body.
Note It is used only if IsStreamed() returned false
.
Reimplemented in server::handlers::DnsClientControl , server::handlers::Jemalloc , server::handlers::DynamicDebugLog , server::handlers::HttpHandlerStatic , server::handlers::LogLevel , server::handlers::OnLogRotate , server::handlers::ServerMonitor , server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType > , server::handlers::HttpHandlerJsonBase , server::handlers::Ping , and server::handlers::ImplicitOptions .
Examples samples/http_caching/http_caching.cpp .
◆ HandleStreamRequest()
The core method for HTTP request handling. request
arg contains HTTP headers, full body, etc. The response body is passed in parts to ResponseBodyStream
. Stream transmission is useful when: 1) The body size is unknown beforehand. 2) The client may take advantage of early body transmission (e.g. a Web Browser may start rendering the HTML page or downloading dependant resources). 3) The body size is huge and we want to have only a part of it in memory.
Note It is used only if IsStreamed() returned true
.
◆ HandleUnknownException()
void server::handlers::HttpHandlerBase::HandleUnknownException
(
const http::HttpRequest & request ,
const std::exception & ex ) const
Takes the exception and formats it into response as an internal server error.
◆ IsMethodStatisticIncluded()
virtual bool server::handlers::HttpHandlerBase::IsMethodStatisticIncluded
(
)
const
inline protected virtual
Override it to show per HTTP-method statistics besides statistics for all methods
Definition at line 161 of file http_handler_base.hpp .
◆ IsStreamed()
virtual bool server::handlers::HttpHandlerBase::IsStreamed
(
)
const
inline protected virtual
◆ NeedCheckAuth()
virtual bool server::handlers::HttpHandlerBase::NeedCheckAuth
(
)
const
inline protected virtual
Override it if you want to disable auth checks in handler by some condition
Definition at line 165 of file http_handler_base.hpp .
◆ OnRequestCompleteThrow()
◆ ParseRequestData()
◆ ReportMalformedRequest()
Produces response to a request unrecognized by the protocol based on provided generic response. Does not throw.
Reimplemented from server::handlers::HandlerBase .
◆ middlewares::Auth
friend class middlewares::Auth
friend
◆ middlewares::HandlerAdapter
friend class middlewares::HandlerAdapter
friend
The documentation for this class was generated from the following file: