Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
Middleware.cpp File Reference

Predefined middleware implementations for logging and JWT authentication. More...

#include "http/Middleware.h"
#include "framework_config.h"
#include "DebugTrace.h"
#include <iostream>
#include "http/HttpResponse.h"
#include "http/JsonResponse.h"
#include "framework/AppContext.h"
+ Include dependency graph for Middleware.cpp:

Go to the source code of this file.

Variables

Middleware loggingMiddleware
 

Detailed Description

Author
Ian Archbell

Part of the PicoFramework HTTP server. This module provides two middleware functions:

  • authMiddleware: Checks for a valid JWT in the Authorization header.
  • loggingMiddleware: Logs the HTTP method and path of incoming requests. Both middleware functions are designed to be used in the HTTP request processing pipeline. If the authentication fails, the authMiddleware will respond with an HTTP 401 Unauthorized status.
Version
0.1
Date
2025-03-26
License:\n MIT License

Definition in file Middleware.cpp.

Variable Documentation

◆ loggingMiddleware

Middleware loggingMiddleware
Initial value:
= [](HttpRequest &req, HttpResponse &res, const RouteMatch &)
{
std::cout << "Received request: " << req.getMethod() << " " << req.getPath() << std::endl;
return true;
}
Forward declaration for potential routing needs.
Definition HttpRequest.h:32
const std::string & getMethod() const
Get the HTTP method.
const std::string & getPath() const
Get the parsed request path (without query string).
Represents an HTTP response object.
Represents a match of a route against an incoming HTTP request.
Definition RouteTypes.h:18

Logging middleware that prints the HTTP method and path to the console.

Logging middleware that prints the HTTP method and path to the console.

Examples
/home/runner/work/pico-framework-docs/pico-framework-docs/pico-framework/framework/include/http/Middleware.h.

Definition at line 57 of file Middleware.cpp.

58{
59 std::cout << "Received request: " << req.getMethod() << " " << req.getPath() << std::endl;
60 return true;
61};