lintel 0.2.0
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
lintel::Controller Class Reference

#include <Controller.h>

Inheritance diagram for lintel::Controller:
lintel::GroupProvider lintel::AdminController lintel::ExampleController lintel::HistoryController lintel::MessageQueueController lintel::ProcessController lintel::PropertyController lintel::SharedMemoryController lintel::UserController

Classes

struct  Method
 

Public Member Functions

 Controller (std::shared_ptr< IAuthService > authService)
 
 ~Controller () override=default
 
void setTrustedProxies (std::vector< std::string > trustedProxies)
 
void registerMethods (std::shared_ptr< httplib::Server > &server)
 
- Public Member Functions inherited from lintel::GroupProvider
 GroupProvider ()=default
 
void add (const Group &group)
 
virtual ~GroupProvider ()=default
 
const std::vector< Group > & provide ()
 

Protected Types

enum  HttpType { Get , Put , Post , Delete }
 
using HandlerArgs = void(const httplib::Request &, httplib::Response &)
 
using HandlerWithContentReaderArgs = void(const httplib::Request &, httplib::Response &, const httplib::ContentReader &)
 
using Handler = std::function< HandlerArgs >
 
using HandlerWithContentReader = std::function< HandlerWithContentReaderArgs >
 

Protected Member Functions

std::string clientIpOf (const httplib::Request &request)
 
template<class Type , HttpType httpType>
Type addMethod (const std::string &pattern, Type handler)
 

Static Protected Member Functions

static PagingParams pagingParamsOf (const httplib::Request &request)
 

Protected Attributes

std::shared_ptr< IAuthService > m_authService
 
ClientIpResolver m_ipResolver
 
std::map< HttpType, std::vector< Method > > m_methods
 

Detailed Description

Base class for HTTP controllers with automatic method registration and auth

Member Typedef Documentation

◆ Handler

using lintel::Controller::Handler = std::function<HandlerArgs>
protected

◆ HandlerArgs

using lintel::Controller::HandlerArgs = void(const httplib::Request &, httplib::Response &)
protected

◆ HandlerWithContentReader

◆ HandlerWithContentReaderArgs

using lintel::Controller::HandlerWithContentReaderArgs = void(const httplib::Request &, httplib::Response &, const httplib::ContentReader &)
protected

Member Enumeration Documentation

◆ HttpType

Enumerator
Get 
Put 
Post 
Delete 

Constructor & Destructor Documentation

◆ Controller()

lintel::Controller::Controller ( std::shared_ptr< IAuthService >  authService)
inlineexplicit
Parameters
authServiceauthentication service for access control

◆ ~Controller()

lintel::Controller::~Controller ( )
overridedefault

Member Function Documentation

◆ addMethod()

template<class Type , HttpType httpType>
Type lintel::Controller::addMethod ( const std::string &  pattern,
Type  handler 
)
inlineprotected

Register a handler for a given HTTP method and URL pattern

◆ clientIpOf()

std::string lintel::Controller::clientIpOf ( const httplib::Request &  request)
protected

Determine the client IP address of a request, honoring the X-Forwarded-For header (leftmost entry) only when the direct peer is a configured trusted proxy.

Parameters
requestthe HTTP request
Returns
the client IP address

◆ pagingParamsOf()

static PagingParams lintel::Controller::pagingParamsOf ( const httplib::Request &  request)
staticprotected

Parses keyset-paging query parameters ('after', 'limit').

Parameters
requestthe HTTP request
Returns
the parsed parameters; enabled=false when neither parameter is present
Exceptions
HttpBadRequestExceptionon an invalid 'limit' value

◆ registerMethods()

void lintel::Controller::registerMethods ( std::shared_ptr< httplib::Server > &  server)

Register all collected handler methods with the HTTP server

◆ setTrustedProxies()

void lintel::Controller::setTrustedProxies ( std::vector< std::string >  trustedProxies)

Configure the trusted proxies allowed to forward X-Forwarded-For.

Parameters
trustedProxiesIPs or CIDR ranges (e.g. "10.0.0.0/8")

Member Data Documentation

◆ m_authService

std::shared_ptr<IAuthService> lintel::Controller::m_authService
protected

◆ m_ipResolver

ClientIpResolver lintel::Controller::m_ipResolver
protected

◆ m_methods

std::map<HttpType, std::vector<Method> > lintel::Controller::m_methods
protected

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