#include <userver/server/handlers/http_handler_base.hpp>
Base class for all the Userver HTTP Handlers.
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 | {} |
middlewares.pipeline-builder | name of a component to build a middleware pipeline for this particular handler | default-handler-middleware-pipeline-builder |
Definition at line 66 of file http_handler_base.hpp.
Public Member Functions | |
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, std::optional< logging::Level > log_level_override={}) const |
Helper function to log an unknown exception. | |
const std::optional< logging::Level > & | GetLogLevel () const |
Returns the default log level for the handler. | |
bool | IsMonitor () const |
Returns whether this is a monitoring handler. | |
const HandlerConfig & | GetConfig () const |
Returns handler config. | |
ComponentHealth | GetComponentHealth () const override |
void | OnLoadingCancelled () override |
void | OnAllComponentsLoaded () override |
void | OnAllComponentsAreStopping () override |
Static Public Member Functions | |
static yaml_config::Schema | GetStaticConfigSchema () |
Protected Types | |
using | HandlerErrorCode = handlers::HandlerErrorCode |
using | InternalMessage = handlers::InternalMessage |
using | ExternalBody = handlers::ExternalBody |
using | ClientError = handlers::ClientError |
using | InternalServerError = handlers::InternalServerError |
using | LoggableComponentBase = ComponentBase |
Legacy alias, use ComponentBase instead. | |
Protected Member Functions | |
void | ThrowUnsupportedHttpMethod (const http::HttpRequest &request) const |
virtual std::string | HandleRequestThrow (const http::HttpRequest &request, request::RequestContext &context) const |
virtual void | HandleStreamRequest (const server::http::HttpRequest &, server::request::RequestContext &, server::http::ResponseBodyStream &) const |
virtual bool | IsStreamed () const |
virtual bool | IsMethodStatisticIncluded () const |
virtual bool | NeedCheckAuth () const |
virtual std::string | GetRequestBodyForLogging (const http::HttpRequest &request, request::RequestContext &context, const std::string &request_body) const |
Override it if you need a custom request body logging. | |
virtual std::string | GetResponseDataForLogging (const http::HttpRequest &request, request::RequestContext &context, const std::string &response_data) const |
Override it if you need a custom response data logging. | |
virtual void | ParseRequestData (const http::HttpRequest &, request::RequestContext &) const |
virtual std::string | GetMetaType (const http::HttpRequest &) const |
|
protectedinherited |
Definition at line 80 of file handler_base.hpp.
|
protectedinherited |
Definition at line 78 of file handler_base.hpp.
|
protectedinherited |
Definition at line 76 of file handler_base.hpp.
|
protectedinherited |
Definition at line 77 of file handler_base.hpp.
|
protectedinherited |
Definition at line 81 of file handler_base.hpp.
|
protectedinherited |
Legacy alias, use ComponentBase instead.
Definition at line 67 of file component_base.hpp.
|
inlineoverridevirtualinherited |
Override this function to inform the world of the state of your component.
Reimplemented from components::RawComponentBase.
Reimplemented in server::handlers::Restart.
Definition at line 35 of file component_base.hpp.
|
virtual |
Override it if you need a custom logging level for messages about finish of request handling for some http statuses.
|
protectedvirtual |
Override it if you need a custom request body logging.
Reimplemented in server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >.
|
protectedvirtual |
Override it if you need a custom response data logging.
Reimplemented in server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >.
void server::handlers::HttpHandlerBase::HandleCustomHandlerException | ( | const http::HttpRequest & | request, |
const CustomHandlerException & | ex ) const |
Takes the exception and formats it into response, as specified by exception.
|
overridevirtual |
Parses request, executes processing routines, and fills response accordingly. Does not throw.
Implements server::handlers::HandlerBase.
|
protectedvirtual |
The core method for HTTP request handling. request
arg contains HTTP headers, full body, etc. The method should return response body.
false
. Reimplemented in server::handlers::DnsClientControl, server::handlers::Jemalloc, server::handlers::Restart, 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.
|
protectedvirtual |
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.
true
. 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.
|
inlineprotectedvirtual |
Override it to show per HTTP-method statistics besides statistics for all methods
Definition at line 154 of file http_handler_base.hpp.
|
inlineinherited |
Returns whether this is a monitoring handler.
Definition at line 67 of file handler_base.hpp.
|
inlineprotectedvirtual |
If IsStreamed() returns true
, call HandleStreamRequest() for request handling, HandleRequestThrow() is not called. If it returns false
, HandleRequestThrow() is called instead, and HandleStreamRequest() is not called.
Definition at line 150 of file http_handler_base.hpp.
|
inlineprotectedvirtual |
Override it if you want to disable auth checks in handler by some condition
Definition at line 158 of file http_handler_base.hpp.
|
inlineoverridevirtualinherited |
Component may use this function to stop doing work before the stop of the components that depend on it.
Base components may override it and make final
to do some work before the derived object constructor is called. Don't use it otherwise.
Reimplemented from components::RawComponentBase.
Reimplemented in urabbitmq::ConsumerComponentBase, and components::Server.
Definition at line 58 of file component_base.hpp.
|
inlineoverridevirtualinherited |
Component may use this function to finalize registration of other components that depend on it (for example, handler components register in server component, and the latter uses OnAllComponentsLoaded() to start processing requests).
Base components may override it and make final
to do some work after the derived object constructor is called. Don't use it otherwise.
Reimplemented from components::RawComponentBase.
Reimplemented in urabbitmq::ConsumerComponentBase, components::Server, and server::handlers::Ping.
Definition at line 51 of file component_base.hpp.
|
inlineoverridevirtualinherited |
Called once if the creation of any other component failed. If the current component expects some other component to take any action with the current component, this call is a signal that such action may never happen due to components loading was cancelled. Application components might not want to override it.
Reimplemented from components::RawComponentBase.
Definition at line 42 of file component_base.hpp.
|
inlineprotectedvirtual |
For internal use. You don't need to override it. This method is overridden in format-specific base handlers.
Reimplemented in server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >, and server::handlers::HttpHandlerJsonBase.
Definition at line 176 of file http_handler_base.hpp.
|
finalvirtual |
Produces response to a request unrecognized by the protocol based on provided generic response. Does not throw.
Reimplemented from server::handlers::HandlerBase.
|
friend |
Definition at line 182 of file http_handler_base.hpp.
|
friend |
Definition at line 181 of file http_handler_base.hpp.