Github   Telegram
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType > Class Template Referenceabstract

Convenient base for handlers that accept requests with body in Flatbuffer format and respond with body in Flatbuffer format. More...

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

+ Inheritance diagram for server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >:
+ Collaboration diagram for server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >:

Public Member Functions

 HttpHandlerFlatbufBase (const components::ComponentConfig &config, const components::ComponentContext &component_context)
 
std::string HandleRequestThrow (const http::HttpRequest &request, request::RequestContext &context) const final
 
virtual ReturnType::NativeTableType HandleRequestFlatbufThrow (const http::HttpRequest &request, const typename InputType::NativeTableType &input, request::RequestContext &context) const =0
 
const InputType::NativeTableType * GetInputData (const request::RequestContext &context) const
 
const ReturnType::NativeTableType * GetOutputData (const request::RequestContext &context) const
 
- 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
 
- Public Member Functions inherited from server::handlers::HandlerBase
 HandlerBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false)
 
virtual void HandleRequest (request::RequestBase &request, request::RequestContext &context) const =0
 
virtual void ReportMalformedRequest (request::RequestBase &) const
 
bool IsMonitor () const
 Returns whether this is a monitoring handler. More...
 
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 ()
 

Protected Member Functions

std::string GetRequestBodyForLogging (const http::HttpRequest &request, request::RequestContext &context, const std::string &request_body) const override
 Override it if you need a custom request body logging. More...
 
std::string GetResponseDataForLogging (const http::HttpRequest &request, request::RequestContext &context, const std::string &response_data) const override
 Override it if you need a custom response data logging. More...
 
void ParseRequestData (const http::HttpRequest &request, request::RequestContext &context) const final
 
- Protected Member Functions inherited from server::handlers::HttpHandlerBase
void ThrowUnsupportedHttpMethod (const http::HttpRequest &request) const
 
virtual std::string HandleRequestThrow (const http::HttpRequest &request, request::RequestContext &context) 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. More...
 
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. More...
 
virtual void ParseRequestData (const http::HttpRequest &, request::RequestContext &) const
 
virtual std::string GetMetaType (const http::HttpRequest &) const
 

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
 

Detailed Description

template<typename InputType, typename ReturnType>
class server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >

Convenient base for handlers that accept requests with body in Flatbuffer format and respond with body in Flatbuffer format.

Example usage:

#include "flatbuffer_schema.fbs.h"
namespace samples::fbs_handle {
class FbsSumEcho final
: public server::handlers::HttpHandlerFlatbufBase<fbs::SampleRequest,
fbs::SampleResponse> {
public:
// `kName` is used as the component name in static config
static constexpr std::string_view kName = "handler-fbs-sample";
// Component is valid after construction and is able to accept requests
FbsSumEcho(const components::ComponentConfig& config,
: HttpHandlerFlatbufBase(config, context) {}
fbs::SampleResponse::NativeTableType HandleRequestFlatbufThrow(
const server::http::HttpRequest& /*request*/,
const fbs::SampleRequest::NativeTableType& fbs_request,
fbs::SampleResponse::NativeTableType res;
res.sum = fbs_request.arg1 + fbs_request.arg2;
res.echo = fbs_request.data;
return res;
}
};
} // namespace samples::fbs_handle
Examples
samples/flatbuf_service/flatbuf_service.cpp.

Definition at line 40 of file http_handler_flatbuf_base.hpp.

Constructor & Destructor Documentation

◆ HttpHandlerFlatbufBase()

template<typename InputType , typename ReturnType >
server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >::HttpHandlerFlatbufBase ( const components::ComponentConfig config,
const components::ComponentContext component_context 
)

Definition at line 86 of file http_handler_flatbuf_base.hpp.

Member Function Documentation

◆ GetInputData()

template<typename InputType , typename ReturnType >
const InputType::NativeTableType * server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >::GetInputData ( const request::RequestContext context) const
Returns
A pointer to input data if it was parsed successfully or nullptr otherwise.

Definition at line 110 of file http_handler_flatbuf_base.hpp.

◆ GetOutputData()

template<typename InputType , typename ReturnType >
const ReturnType::NativeTableType * server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >::GetOutputData ( const request::RequestContext context) const
Returns
a pointer to output data if it was returned successfully by HandleRequestFlatbufThrow() or nullptr otherwise.

Definition at line 118 of file http_handler_flatbuf_base.hpp.

◆ GetRequestBodyForLogging()

template<typename InputType , typename ReturnType >
std::string server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >::GetRequestBodyForLogging ( const http::HttpRequest request,
request::RequestContext context,
const std::string &  request_body 
) const
overrideprotectedvirtual

Override it if you need a custom request body logging.

Reimplemented from server::handlers::HttpHandlerBase.

Definition at line 126 of file http_handler_flatbuf_base.hpp.

◆ GetResponseDataForLogging()

template<typename InputType , typename ReturnType >
std::string server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >::GetResponseDataForLogging ( const http::HttpRequest request,
request::RequestContext context,
const std::string &  response_data 
) const
overrideprotectedvirtual

Override it if you need a custom response data logging.

Reimplemented from server::handlers::HttpHandlerBase.

Definition at line 135 of file http_handler_flatbuf_base.hpp.

◆ GetStaticConfigSchema()

template<typename InputType , typename ReturnType >
yaml_config::Schema server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >::GetStaticConfigSchema
static

Definition at line 162 of file http_handler_flatbuf_base.hpp.

◆ HandleRequestThrow()

template<typename InputType , typename ReturnType >
std::string server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >::HandleRequestThrow ( const http::HttpRequest request,
request::RequestContext context 
) const
finalvirtual

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.

Definition at line 92 of file http_handler_flatbuf_base.hpp.

◆ ParseRequestData()

template<typename InputType , typename ReturnType >
void server::handlers::HttpHandlerFlatbufBase< InputType, ReturnType >::ParseRequestData ( const http::HttpRequest ,
request::RequestContext  
) const
finalprotectedvirtual

For internal use. You don't need to override it. This method is overriden in format-specific base handlers.

Reimplemented from server::handlers::HttpHandlerBase.

Definition at line 143 of file http_handler_flatbuf_base.hpp.


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