#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 {}
middlewares.pipeline-builder name of a component to build a middleware pipeline for this particular handler default-handler-middleware-pipeline-builder
Example usage:
#pragma once
namespace samples::hello {
public :
static constexpr std::string_view kName = "handler-hello-sample" ;
using HttpHandlerBase::HttpHandlerBase;
};
}
#include "hello_handler.hpp"
#include "say_hello.hpp"
namespace samples::hello {
std::string
const {
request .GetHttpResponse().SetContentType(http::content_type::kTextPlain);
return samples::hello::SayHelloTo(
request .GetArg(
"name" ));
}
}
Examples postgresql/functional_tests/basic_chaos/postgres_service.cpp , samples/hello_service/src/hello_handler.hpp , samples/http_caching/main.cpp , samples/mongo_service/main.cpp , samples/multipart_service/main.cpp , samples/postgres_auth/postgres_service.cpp , samples/postgres_service/main.cpp , and samples/redis_service/main.cpp .
Definition at line 65 of file http_handler_base.hpp .
◆ ClientError
◆ ExternalBody
◆ HandlerErrorCode
◆ InternalMessage
◆ InternalServerError
◆ LoggableComponentBase
◆ GetComponentHealth()
ComponentHealth components::ComponentBase::GetComponentHealth
(
)
const
inline override virtual inherited
◆ 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()
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
.
Examples samples/http_caching/main.cpp .
◆ HandleRequestThrow()
Same as HandleRequest
.
Reimplemented in server::handlers::DnsClientControl , server::handlers::DynamicDebugLog , server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType > , server::handlers::HttpHandlerJsonBase , server::handlers::HttpHandlerStatic , server::handlers::ImplicitOptions , server::handlers::Jemalloc , server::handlers::LogLevel , server::handlers::OnLogRotate , server::handlers::Ping , server::handlers::Restart , and server::handlers::ServerMonitor .
◆ 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 156 of file http_handler_base.hpp .
◆ IsMonitor()
bool server::handlers::HandlerBase::IsMonitor
(
)
const
inline inherited
Returns whether this is a monitoring handler.
Definition at line 67 of file 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 160 of file http_handler_base.hpp .
◆ OnAllComponentsAreStopping()
void components::ComponentBase::OnAllComponentsAreStopping
(
)
inline override virtual inherited
◆ OnAllComponentsLoaded()
void components::ComponentBase::OnAllComponentsLoaded
(
)
inline override virtual inherited
◆ OnLoadingCancelled()
void components::ComponentBase::OnLoadingCancelled
(
)
inline override virtual inherited
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 .
◆ ParseRequestData()
◆ PrepareAndHandleRequest()
◆ ReportMalformedRequest()
void server::handlers::HttpHandlerBase::ReportMalformedRequest
(
http::HttpRequest & )
const
final virtual
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: