Middleware definitions for HTTP routing (e.g., logging, auth). Part of the PicoFramework HTTP server. This module defines middleware functions that can be used in the HTTP request processing pipeline. Middleware can perform tasks such as authentication, logging, and modifying requests or responses before passing them to the next handler in the chain. Middleware functions are designed to be composable, allowing multiple middleware components to be applied in sequence. Each middleware function can either allow the request to continue to the next handler or stop further processing based on certain conditions. More...
#include "HttpRequest.h"
#include "HttpResponse.h"
#include "JwtAuthenticator.h"
#include <functional>
#include <vector>
#include "router.h"
Go to the source code of this file.
Typedefs | |
using | Middleware = std::function< bool(HttpRequest &, HttpResponse &, const RouteMatch &)> |
Function signature for middleware components. | |
Variables | |
Middleware | authMiddleware |
Middleware | loggingMiddleware |
Logging middleware that prints the HTTP method and path to the console. | |
To create your own middleware:
Definition in file Middleware.h.
using Middleware = std::function<bool(HttpRequest &, HttpResponse &, const RouteMatch &)> |
Middleware functions operate on the request and response objects. They return true
to allow processing to continue, or false
to stop further middleware and route execution.
req | The incoming HTTP request. |
res | The HTTP response being constructed. |
params | Path parameters captured by the router. |
Definition at line 50 of file Middleware.h.
|
extern |
|
extern |
This middleware always allows processing to continue.
Logging middleware that prints the HTTP method and path to the console.
Logging middleware that prints the HTTP method and path to the console.
Definition at line 57 of file Middleware.cpp.