Built-in middleware components for Orbit HTTP server.
More...
Built-in middleware components for Orbit HTTP server.
◆ JsonType
Enumeration of JSON data types.
| Enumerator |
|---|
| STRING | |
| NUMBER | |
| BOOLEAN | |
| OBJECT | |
| ARRAY | |
◆ compress()
Returns a middleware that automatically compresses the HTTP response body using GZIP.
Compresses the response if the client sent the Accept-Encoding: gzip header.
- Returns
- routing::Middleware The compression middleware handler.
◆ cors()
Returns a middleware that handles CORS.
- Parameters
-
| options | The CORS configuration options. |
- Returns
- routing::Middleware The CORS middleware handler.
◆ csrf_protection()
| auto middleware::csrf_protection |
( |
const std::string & |
cookie_name = "csrf_token", |
|
|
const std::string & |
header_name = "X-CSRF-Token" |
|
) |
| |
|
inline |
Helper to create a CSRF protection middleware handler.
- Parameters
-
| cookie_name | The name of the cookie to store the CSRF token. |
| header_name | The name of the header expected in requests. |
- Returns
- A middleware handler function.
◆ distributed_rate_limit()
| auto middleware::distributed_rate_limit |
( |
const std::string & |
redis_host, |
|
|
int |
redis_port, |
|
|
size_t |
max_requests, |
|
|
std::chrono::seconds |
window |
|
) |
| |
|
inline |
Helper to create a distributed rate limiting middleware handler.
- Parameters
-
| redis_host | The Redis server host. |
| redis_port | The Redis server port. |
| max_requests | Maximum number of requests allowed in the time window. |
| window | The time window for rate limiting. |
- Returns
- A middleware handler function.
◆ jwt_auth()
JWT Authentication middleware using HMAC-SHA256 (HS256).
Verifies the "Authorization: Bearer <token>" header against the secret key. If valid, the decoded JSON payload is placed into HttpRequest::user. If invalid or missing, it responds with a 401 Unauthorized and stops the pipeline.
routing::Middleware jwt_auth(const std::string &secret_key)
JWT Authentication middleware using HMAC-SHA256 (HS256).
Definition JwtAuth.cpp:65
- Parameters
-
| secret_key | The secret key used for HMAC-SHA256 verification. |
- Returns
- routing::Middleware The JWT authentication middleware handler.
◆ load_balancer() [1/2]
Returns a middleware that load-balances requests across multiple upstream nodes.
- Parameters
-
| nodes | A vector of target nodes. |
- Returns
- routing::Middleware The load balancer middleware handler.
◆ load_balancer() [2/2]
Returns a middleware that load-balances requests across multiple upstream nodes.
Currently implements a Round-Robin algorithm.
- Parameters
-
| options | The load balancer options. |
- Returns
- routing::Middleware The load balancer middleware handler.
◆ proxy() [1/2]
Returns a middleware that proxies requests to a single target URL.
- Parameters
-
| target_host | The target host. |
| target_port | The target port. |
- Returns
- routing::Middleware The proxy middleware handler.
◆ proxy() [2/2]
Returns a middleware that proxies requests to a single target URL (ip/hostname and port).
- Parameters
-
| options | The proxy configuration options. |
- Returns
- routing::Middleware The proxy middleware handler.
◆ rate_limit()
| auto middleware::rate_limit |
( |
size_t |
max_requests, |
|
|
std::chrono::seconds |
window |
|
) |
| |
|
inline |
Helper function to easily register rate limiting middleware.
- Parameters
-
| max_requests | Maximum number of requests allowed in the time window. |
| window | The time window for rate limiting. |
- Returns
- A middleware handler function.
◆ session()
| auto middleware::session |
( |
const std::string & |
redis_host, |
|
|
int |
redis_port |
|
) |
| |
|
inline |
Helper to create a session management middleware handler.
- Parameters
-
| redis_host | The Redis server host. |
| redis_port | The Redis server port. |
- Returns
- A middleware handler function.
◆ static_files()
Returns a middleware that serves static files from a directory.
If a file is found, it is served and the pipeline is stopped. If a file is not found, the pipeline continues.
- Parameters
-
| directory | The directory containing static files. |
- Returns
- routing::Middleware The static files middleware handler.
◆ validate_json()
Returns a middleware that parses and validates a JSON request body.
If valid, the parsed JSON is available in req.json_body. If invalid, it intercepts the request and responds with a 422 Unprocessable Entity.
- Parameters
-
| schema | The schema to validate against. |
- Returns
- routing::Middleware The validation middleware handler.