Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
HttpServer.h
Go to the documentation of this file.
1
13#ifndef HTTP_SERVER_H
14#define HTTP_SERVER_H
15#pragma once
16
17#include <string>
18#include <unordered_map>
19#include "Router.h"
20#include "FreeRTOS.h"
21#include "task.h"
22
23#define HTTP_STACK_SIZE 10 * 1024 / sizeof(StackType_t) // Stack size for FreeRTOS task
24
29{
30public:
37
42 bool start();
43
48 bool initNetwork();
49
53 void run();
54
59 static void startServerTask(void *pvParameters);
60
66
71 void handleClient(Tcp *conn);
72
77 void startHandlingClient(Tcp* conn);
78
89 HttpRequest receiveRequest(Tcp* conn, char* method, char* path, std::string& body,
90 size_t& contentLength, std::unordered_map<std::string, std::string>& headers);
91
96 Router &getRouter() { return router; }
97
102 static void handleClientTask(void *pvParameters);
103
107 //void acceptClientConnections(); // Handled in run()
108
109private:
110 int port;
112
113 Tcp listener; // Listening insance of Tcp class
114 static constexpr int BUFFER_SIZE = 1460;
115 static constexpr int BOUNDARY_MAX_LEN = 128;
116
117 static StackType_t xStack[HTTP_STACK_SIZE];
118 static StaticTask_t xTaskBuffer;
119};
120
121#endif // HTTP_SERVER_H
#define HTTP_STACK_SIZE
Definition HttpServer.h:23
HTTP routing with middleware and optional JWT-based authorization. Part of the PicoFramework HTTP ser...
Forward declaration for potential routing needs.
Definition HttpRequest.h:32
HTTP Server that listens for incoming connections and dispatches requests.
Definition HttpServer.h:29
bool initNetwork()
Initialize the network stack (wait for DHCP or static IP).
static void startServerTask(void *pvParameters)
Launch the HTTP server task (used by FreeRTOS).
HttpRequest receiveRequest(Tcp *conn, char *method, char *path, std::string &body, size_t &contentLength, std::unordered_map< std::string, std::string > &headers)
Receive an HTTP request and parse key components.
static constexpr int BUFFER_SIZE
Definition HttpServer.h:114
void handleClient(Tcp *conn)
Accept a client connection and handle it directly (not task-based).
static StackType_t xStack[HTTP_STACK_SIZE]
Stack for static FreeRTOS task.
Definition HttpServer.h:117
static constexpr int BOUNDARY_MAX_LEN
Definition HttpServer.h:115
Router & getRouter()
Return the router associated with the server.
Definition HttpServer.h:96
Tcp * initListener()
Create, bind, and listen on the server.
int port
Accept client connections in a blocking loop and spawn handlers.
Definition HttpServer.h:110
void startHandlingClient(Tcp *conn)
Spawn a task to handle the client connection.
Router & router
Reference to router for dispatching requests.
Definition HttpServer.h:111
static void handleClientTask(void *pvParameters)
Handle client logic inside a FreeRTOS task.
static StaticTask_t xTaskBuffer
Task control block buffer.
Definition HttpServer.h:118
bool start()
Start the HTTP server as a FreeRTOS task.
void run()
Main server loop: initializes, binds, and begins accepting connections.
The central router for handling HTTP requests and middleware.
Definition Router.h:60
General-purpose TCP socket wrapper with optional TLS support via mbedTLS (altcp).
Definition Tcp.h:39