Handler that returns HTTP 200 if file exist and returns file data with mapped content/type.
Path arguments of this handle are passed to fs-cache-component to get the file. In other words, for the following fs-cache-main:
fs-cache-main:
dir: /fs-cache-main-path/ # Path to the directory with files
the handler-static with path: /handler-static-path/* on request to /handler-static-path/some/file.html would return file at path /fs-cache-main-path/some/file.html.
HttpHandlerStatic Dynamic config
Userver HTTP Handlers.
Static options of server::handlers::HttpHandlerStatic :
| Name | Description | Default value |
| fs-cache-component | Name of the FsCache component. | fs-cache-component |
| expires | Cache age in seconds. | 600 |
| directory-file | File to return for directory requests. File name (not path) search in requested directory. | index.html |
| not-found-file | File to return for missing files. | /404.html |
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 |
Example usage:
int main(int argc, char* argv[]) {
const auto component_list =
.
Append<MessagesHandler>(
"handler-messages")
.Append<components::FsCache>("fs-cache-main")
}
- Examples
- samples/static_service/main.cpp.
Definition at line 48 of file http_handler_static.hpp.
|
|
| HttpHandlerStatic (const components::ComponentConfig &config, const components::ComponentContext &context) |
| |
| std::string | HandleRequestThrow (const http::HttpRequest &request, request::RequestContext &) const override |
| | Same as HandleRequest.
|
| |
|
| HttpHandlerBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false) |
| |
| 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 |
| |
|
|
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 |
| |
| void components::ComponentBase::OnAllComponentsLoaded |
( |
| ) |
|
|
inlineoverridevirtualinherited |