userver: server::handlers::ImplicitOptions Class Reference
Loading...
Searching...
No Matches
server::handlers::ImplicitOptions Class Reference

#include <userver/server/handlers/implicit_options.hpp>

Detailed Description

A "magical" handler that will respond to OPTIONS HTTP method for any other handler that cannot handle OPTIONS itself.

It returns Allow header, listing all the methods that are supported for the given HTTP path, including OPTIONS itself.

Auth checker testing

In addition to the above RFC behavior, an optional extension is supported. If auth_checkers static config option is specified, http::headers::kXYaTaxiAllowAuthRequest header can be passed containing the checker key in the static config.

The request will then be passed as-is to the auth checker. The result of the check will be returned in http::headers::kXYaTaxiAllowAuthResponse header. The following responses are possible:

  • unknown checker if the checker is not found
  • OK if the check succeeds
  • an unspecified error message if the check fails

Static options

The component has no service configuration except the common handler options. and adds the following ones:

Name Description Default value
auth server::handlers::auth::HandlerAuthConfig authorization config auth checker testing is disabled

Static configuration example:

# yaml
handler-implicit-http-options:
as_fallback: implicit-http-options
method: OPTIONS
task_processor: main-task-processor

Scheme

Provide an optional query parameter body to get the bodies of all the in-flight requests.

Definition at line 69 of file implicit_options.hpp.

+ Inheritance diagram for server::handlers::ImplicitOptions:
+ Collaboration diagram for server::handlers::ImplicitOptions:

Public Member Functions

 ImplicitOptions (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false)
 
std::string HandleRequestThrow (const server::http::HttpRequest &request, server::request::RequestContext &context) const override
 
- Public Member Functions inherited from server::handlers::HttpHandlerBase
 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 HandlerConfigGetConfig () const
 Returns handler config.
 
- Public Member Functions inherited from components::LoggableComponentBase
 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
 

Static Public Member Functions

static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from server::handlers::HttpHandlerBase
static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from server::handlers::HandlerBase
static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from components::LoggableComponentBase
static yaml_config::Schema GetStaticConfigSchema ()
 

Static Public Attributes

static constexpr std::string_view kName = "handler-implicit-http-options"
 The default name of server::handlers::ImplicitOptions component.
 

Additional Inherited Members

- Protected Types inherited from server::handlers::HandlerBase
using HandlerErrorCode = handlers::HandlerErrorCode
 
using InternalMessage = handlers::InternalMessage
 
using ExternalBody = handlers::ExternalBody
 
using ClientError = handlers::ClientError
 
using InternalServerError = handlers::InternalServerError
 
- Protected Member Functions inherited from server::handlers::HttpHandlerBase
void ThrowUnsupportedHttpMethod (const http::HttpRequest &request) const
 
virtual void OnRequestCompleteThrow (const http::HttpRequest &, request::RequestContext &) 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
 

Member Function Documentation

◆ HandleRequestThrow()

std::string server::handlers::ImplicitOptions::HandleRequestThrow ( const server::http::HttpRequest & request,
server::request::RequestContext & context ) const
overridevirtual

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 from server::handlers::HttpHandlerBase.


The documentation for this class was generated from the following file: