Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
Loading...
Searching...
No Matches
middleware Namespace Reference

Classes

struct  CorsOptions
 Options for configuring CORS (Cross-Origin Resource Sharing). More...
 
class  Csrf
 Cross-Site Request Forgery (CSRF) protection middleware. More...
 
class  DistributedRateLimiter
 Distributed rate limiter middleware using Redis. More...
 
struct  LoadBalancerOptions
 Options for LoadBalancer middleware. More...
 
class  Metrics
 Middleware for tracking HTTP request metrics. More...
 
class  OAuth2
 Middleware for handling OAuth2 authentication. More...
 
struct  OAuth2Config
 Configuration for OAuth2 middleware. More...
 
struct  ProxyOptions
 Options for Proxy middleware. More...
 
class  ProxyRequest
 
class  RateLimiter
 Middleware for in-memory rate limiting. More...
 
struct  SchemaField
 Represents a field in a validation schema. More...
 
class  SessionManager
 Middleware for managing sessions using Redis. More...
 
struct  TargetNode
 A target node for the load balancer. More...
 

Typedefs

using GraphQLExecutor = std::function< nlohmann::json(const std::string &query, const std::string &operation_name, const nlohmann::json &variables)>
 Signature for a GraphQL executor function. Takes the query string, operation name (optional), and variables (optional), and returns a JSON response (which should have "data" or "errors").
 

Enumerations

enum class  JsonType {
  JsonType::STRING , JsonType::NUMBER , JsonType::BOOLEAN , JsonType::OBJECT ,
  JsonType::ARRAY
}
 Enumeration of JSON data types. More...
 

Functions

routing::Middleware compress ()
 Returns a middleware that automatically compresses the HTTP response body using GZIP.
 
routing::Middleware cors (CorsOptions options=CorsOptions{})
 Returns a middleware that handles CORS.
 
auto csrf_protection (const std::string &cookie_name="csrf_token", const std::string &header_name="X-CSRF-Token")
 Helper to create a CSRF protection middleware handler.
 
auto distributed_rate_limit (const std::string &redis_host, int redis_port, size_t max_requests, std::chrono::seconds window)
 Helper to create a distributed rate limiting middleware handler.
 
std::function< bool(http::HttpRequest &, std::shared_ptr< http::ResponseWriter >)> graphql (GraphQLExecutor executor)
 Creates a middleware handler for GraphQL endpoints. It parses the incoming GET or POST request according to the GraphQL over HTTP spec, extracts the query, operationName, and variables, and invokes the provided executor.
 
routing::Middleware jwt_auth (const std::string &secret_key)
 JWT Authentication middleware using HMAC-SHA256 (HS256).
 
routing::Middleware proxy (ProxyOptions options)
 Returns a middleware that proxies requests to a single target URL (ip/hostname and port).
 
routing::Middleware proxy (const std::string &target_host, int target_port)
 Returns a middleware that proxies requests to a single target URL.
 
routing::Middleware load_balancer (LoadBalancerOptions options)
 Returns a middleware that load-balances requests across multiple upstream nodes.
 
routing::Middleware load_balancer (const std::vector< TargetNode > &nodes)
 Returns a middleware that load-balances requests across multiple upstream nodes.
 
auto rate_limit (size_t max_requests, std::chrono::seconds window)
 Helper function to easily register rate limiting middleware.
 
auto session (const std::string &redis_host, int redis_port)
 Helper to create a session management middleware handler.
 
routing::Middleware static_files (const std::string &directory)
 Returns a middleware that serves static files from a directory.
 
routing::Middleware validate_json (const std::vector< SchemaField > &schema)
 Returns a middleware that parses and validates a JSON request body.
 
static std::string base64url_encode (const unsigned char *input, int length)
 
static std::string base64url_decode (const std::string &input)
 
static bool verify_jwt_signature (const std::string &header_b64, const std::string &payload_b64, const std::string &provided_signature, const std::string &secret)
 

Variables

static std::unique_ptr< network::ClientTlsContextg_proxy_tls
 
static std::once_flag g_proxy_tls_flag
 

Typedef Documentation

◆ GraphQLExecutor

using middleware::GraphQLExecutor = typedef std::function<nlohmann::json(const std::string& query, const std::string& operation_name, const nlohmann::json& variables)>

Signature for a GraphQL executor function. Takes the query string, operation name (optional), and variables (optional), and returns a JSON response (which should have "data" or "errors").

Function Documentation

◆ base64url_decode()

static std::string middleware::base64url_decode ( const std::string &  input)
static

◆ base64url_encode()

static std::string middleware::base64url_encode ( const unsigned char *  input,
int  length 
)
static

◆ graphql()

std::function< bool(http::HttpRequest &, std::shared_ptr< http::ResponseWriter >)> middleware::graphql ( GraphQLExecutor  executor)
inline

Creates a middleware handler for GraphQL endpoints. It parses the incoming GET or POST request according to the GraphQL over HTTP spec, extracts the query, operationName, and variables, and invokes the provided executor.

Parameters
executorThe user-provided GraphQL execution engine function.

◆ verify_jwt_signature()

static bool middleware::verify_jwt_signature ( const std::string &  header_b64,
const std::string &  payload_b64,
const std::string &  provided_signature,
const std::string &  secret 
)
static

Variable Documentation

◆ g_proxy_tls

std::unique_ptr<network::ClientTlsContext> middleware::g_proxy_tls
static

◆ g_proxy_tls_flag

std::once_flag middleware::g_proxy_tls_flag
static