#include <userver/server/handlers/ping.hpp>
Base class for handlers that returns HTTP 200 if the service is OK and able to process requests.
Uses components::State::IsAnyComponentInFatalState() to detect fatal state (can not process requests).
Options inherited from server::handlers::HttpHandlerBase :
| Name | Description | Default value |
|---|---|---|
| log-level | Overrides log level for this handle. | <no override> |
| status-codes-log-level.* | HTTP status code -> log level map. Each of the elements: log level. | – |
| middlewares.pipeline-builder | Name of a component to build a middleware pipeline for this particular handler. | default-handler-middleware-pipeline-builder |
| middlewares.*.* | Per-middleware configuration. | – |
Options inherited from server::handlers::HandlerBase :
| Name | Description | Default value |
|---|---|---|
| path | If a request matches this path wildcard then process it by handler. | – |
| as_fallback | Set to "implicit-http-options" and do not specify a path if this handler processes the OPTIONS requests for paths that do not process OPTIONS method. Possible values: implicit-http-options, unknown. | – |
| task_processor | A task processor to execute the requests. | the 'default_task_processor' value from components::ManagerControllerComponent |
| method | Comma-separated list of allowed methods. | – |
| max_request_size | Maximum size of the whole request. Limits both the size of the request and the size of a decompressed request body (if compression is being used). Requests exceeding the limit are rejected with 'Request Entity Too Large' (413) HTTP code. | 1024 * 1024 |
| max_headers_size | Max request headers size of empty to do not limit. | 65536 |
| parse_args_from_body | Optional field to parse request according to x-www-form-urlencoded rules and make parameters accessible as query parameters. | false |
| auth.type | Auth type. | – |
| auth.types.[] | List of auth types. Each of the elements: auth type. | – |
| auth.* | Server::handlers::auth::HandlerAuthConfig authorization config. | – |
| url_trailing_slash | 'both' to treat URLs with and without a trailing slash as equal, 'strict-match' otherwise. Possible values: both, strict-match. | both |
| max_requests_in_flight | Integer to limit max pending requests to this handler. | <no limit> |
| request_body_size_log_limit | Trim the request to this size before logging. | 512 |
| request_headers_size_log_limit | Trim request headers to this size before logging. | 512 |
| response_data_size_log_limit | Trim responses to this size before logging. | 512 |
| max_requests_per_second | Integer to limit RPS to this handler. | <no limit> |
| decompress_request | Allow decompression of the requests. | true |
| throttling_enabled | Allow throttling of the requests by components::Server , for more info see its max_response_size_in_flight and requests_queue_size_threshold options. | true |
| set-response-server-hostname | Set to true to add the X-YaTaxi-Server-Hostname header with instance name, set to false to not add the header. | <takes the value from components::Server config> |
| response-body-stream | TODO. | false |
| monitor-handler | Overrides the in-code is_monitor flag that makes the handler run either on 'server.listener' or on 'server.listener-monitor'. | uses in-code flag value |
| set_tracing_headers | Whether to set http tracing headers (X-YaTraceId, X-YaSpanId, X-RequestId). | true |
| deadline_propagation_enabled | When set to false, disables deadline propagation within this handler. This includes: - reading the task-inherited deadline from HTTP headers and gRPC metadata; - interrupting operations when deadline expires; - propagating the deadline to downstream services and databases. Deadline propagation can also be disabled in the static config of: - components::Server (to set the default for all HTTP handlers). Deadline propagation is disabled if disabled statically OR dynamically. | true |
| deadline_expired_status_code | The HTTP status code to return if the request deadline expires. | taken from server.listener.handler-defaults.deadline_expired_status_code |
| enable_write_statistics | Whether to write handler statistics. | true |
Options inherited from components::ComponentBase :
| Name | Description | Default value |
|---|---|---|
| load-enabled | Set to false to disable loading of the component. | true |
Inheritance diagram for server::handlers::PingBase:Public Member Functions | |
| PingBase (const components::ComponentConfig &config, const components::ComponentContext &component_context) | |
| std::string | HandleRequestThrow (const http::HttpRequest &request, request::RequestContext &context) const override |
Same as HandleRequest. | |
| void | PrepareAndHandleRequest (http::HttpRequest &request, request::RequestContext &context) const override |
| void | ReportMalformedRequest (http::HttpRequest &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 |
| std::string | GetUrlForLoggingChecked (const http::HttpRequest &request, request::RequestContext &context) const |
| void | HandleCustomHandlerException (const http::HttpRequest &request, request::RequestContext &context, const CustomHandlerException &ex) const |
| void | HandleUnknownException (const http::HttpRequest &request, request::RequestContext &context, 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 |
Protected Member Functions | |
| void | ThrowUnsupportedHttpMethod (const http::HttpRequest &request) const |
| virtual std::string | HandleRequest (http::HttpRequest &request, request::RequestContext &context) const |
| virtual void | HandleStreamRequest (server::http::HttpRequest &, server::request::RequestContext &, server::http::ResponseBodyStream &) const |
| virtual bool | IsStreamed () const |
| virtual bool | IsStreamed (const http::HttpRequest &, server::request::RequestContext &) 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 std::string | GetUrlForLogging (const http::HttpRequest &request, request::RequestContext &context) const |
| Override it if you need a custom request url logging. | |
| virtual void | ParseRequestData (const http::HttpRequest &, request::RequestContext &) const |
| virtual std::string | GetMetaType (const http::HttpRequest &) const |
|
protectedinherited |
Definition at line 57 of file handler_base.hpp.
|
protectedinherited |
Definition at line 55 of file handler_base.hpp.
|
protectedinherited |
Definition at line 53 of file handler_base.hpp.
|
protectedinherited |
Definition at line 54 of file handler_base.hpp.
|
protectedinherited |
Definition at line 58 of file handler_base.hpp.
|
protectedinherited |
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.
|
virtualinherited |
Override it if you need a custom logging level for messages about finish of request handling for some http statuses.
|
protectedvirtualinherited |
Override it if you need a custom request body logging.
Reimplemented in server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >.
|
protectedvirtualinherited |
Override it if you need a custom response data logging.
Reimplemented in server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >.
|
inherited |
Takes the exception and formats it into response, as specified by exception.
|
protectedvirtualinherited |
The core method for HTTP request handling. request arg contains HTTP headers, full body, etc. The method should return response body.
false.
|
overridevirtual |
Same as HandleRequest.
Reimplemented from server::handlers::HttpHandlerBase.
|
protectedvirtualinherited |
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.
|
inherited |
Takes the exception and formats it into response as an internal server error.
|
inlineprotectedvirtualinherited |
Override it to show per HTTP-method statistics besides statistics for all methods
Definition at line 163 of file http_handler_base.hpp.
|
inlineinherited |
Returns whether this is a monitoring handler.
Definition at line 44 of file handler_base.hpp.
|
inlineprotectedvirtualinherited |
If IsStreamed() returns true, call HandleStreamRequest() for request handling, HandleRequest() is not called. If it returns false, HandleRequest() is called instead, and HandleStreamRequest() is not called.
Definition at line 154 of file http_handler_base.hpp.
|
inlineprotectedvirtualinherited |
Override it if you need a custom streamed logic based on request and context.
Definition at line 159 of file http_handler_base.hpp.
|
inlineprotectedvirtualinherited |
Override it if you want to disable auth checks in handler by some condition
Definition at line 167 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 components::Server, and urabbitmq::ConsumerComponentBase.
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 components::Server, server::handlers::Ping, and urabbitmq::ConsumerComponentBase.
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.
|
inlineprotectedvirtualinherited |
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 188 of file http_handler_base.hpp.
|
overridevirtualinherited |
Parses request, executes processing routines, and fills response accordingly. Does not throw.
Implements server::handlers::HandlerBase.
|
finalvirtualinherited |
Produces response to a request unrecognized by the protocol based on provided generic response. Does not throw. The error should be stored into response status and body prior to this call.
Reimplemented from server::handlers::HandlerBase.