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

HTTP routing with middleware and optional JWT-based authorization. More...

#include "framework_config.h"
#include "DebugTrace.h"
#include <regex>
#include "http/Router.h"
#include "http/HttpRequest.h"
#include "http/HttpResponse.h"
#include "http/JwtAuthenticator.h"
#include "http/Middleware.h"
#include "utility/utility.h"
#include "http/url_utils.h"
#include "http/JsonResponse.h"
#include "framework/AppContext.h"
+ Include dependency graph for Router.cpp:

Go to the source code of this file.

Functions

static std::string extractBearerToken (const std::string &auth_header)
 

Variables

SemaphoreHandle_t lock_
 

Detailed Description

Author
Ian Archbell

Part of the PicoFramework HTTP server. This module provides the Router class, which manages HTTP routes, middleware, and optional JWT authentication. It allows dynamic route registration, regex-based path matching, and supports global and per-route middleware. The Router can handle requests, invoke appropriate handlers, and apply middleware functions in sequence. It also includes a built-in route handler for testing JWT tokens at the /auth endpoint.

Version
0.2
Date
2025-03-26

Improvements:

  • Unified token extraction via helper function.
  • Removed token caching to avoid cross-request issues.
  • Fixed auth check bug.
  • Streamlined route registration and logging.
License:\n MIT License

Definition in file Router.cpp.

Function Documentation

◆ extractBearerToken()

static std::string extractBearerToken ( const std::string &  auth_header)
static

Definition at line 49 of file Router.cpp.

50{
51 const std::string bearerPrefix = "Bearer ";
52 if (auth_header.compare(0, bearerPrefix.size(), bearerPrefix) == 0)
53 {
54 return auth_header.substr(bearerPrefix.size());
55 }
56 return "";
57}

Referenced by Router::getAuthorizationToken().

+ Here is the caller graph for this function:

Variable Documentation

◆ lock_

SemaphoreHandle_t lock_

Definition at line 44 of file Router.cpp.