11 #ifndef COMPONENTS_CPP_UTILS_HTTPSERVER_H_
12 #define COMPONENTS_CPP_UTILS_HTTPSERVER_H_
17 #include "HttpRequest.h"
18 #include "HttpResponse.h"
31 std::string pathPattern,
32 void (*pWebServerRequestHandler)
39 std::regex* pathPattern,
40 void (*pWebServerRequestHandler)
45 bool match(std::string method, std::string path);
51 std::string m_textPattern;
64 void (*webServerRequestHandler)
72 void (*webServerRequestHandler)
86 void start(uint16_t portNumber,
bool useSSL =
false);
92 void listDirectory(std::string path,
HttpResponse& response);
93 size_t m_fileBufferSize;
94 bool m_directoryListing;
95 std::vector<PathHandler> m_pathHandlers;
96 uint16_t m_portNumber;
97 std::string m_rootPath;
100 uint32_t m_clientTimeout;
Encapsulate a socket.
Definition: Socket.h:62
void addPathHandler(std::string method, std::string pathExpr, void(*webServerRequestHandler)(HttpRequest *pHttpRequest, HttpResponse *pHttpResponse))
Register a handler for a path.
Definition: HttpServer.cpp:215
std::string getRootPath()
Get the current root path.
Definition: HttpServer.cpp:250
Handle path matching for an incoming HTTP request.
Definition: HttpServer.h:27
bool getSSL()
Return whether or not we are using SSL.
Definition: HttpServer.cpp:259
HttpServer()
Definition: HttpServer.cpp:32
uint16_t getPort()
Get the port number on which the HTTP Server is listening.
Definition: HttpServer.cpp:241
void setRootPath(std::string path)
Set the root path for URL file mapping.
Definition: HttpServer.cpp:371
void stop()
Shutdown the HTTP server.
Definition: HttpServer.cpp:412
void start(uint16_t portNumber, bool useSSL=false)
Start the HTTP server listening. We start an instance of the HTTP server listening. A new task is spawned to perform this work in the back ground.
Definition: HttpServer.cpp:388
bool match(std::string method, std::string path)
Determine if the path matches.
Definition: HttpServer.cpp:472
Definition: WebSocket.h:60
void setClientTimeout(uint32_t timeout)
Set different socket timeout for new connections.
Definition: HttpServer.cpp:319
PathHandler(std::string method, std::string pathPattern, void(*pWebServerRequestHandler)(HttpRequest *pHttpRequest, HttpResponse *pHttpResponse))
Construct an instance of a PathHandler.
Definition: HttpServer.cpp:451
Definition: HttpServer.h:56
Be an HTTP server task. Here we define a Task that will be run when the HTTP server starts...
Definition: HttpServer.cpp:53
size_t getFileBufferSize()
Get the size of the file buffer. When serving up a file from the file system, we can't afford to read...
Definition: HttpServer.cpp:232
uint32_t getClientTimeout()
Get current socket's timeout for new connections.
Definition: HttpServer.cpp:328
Definition: HttpRequest.h:19
Definition: FreeRTOS.h:31
void invokePathHandler(HttpRequest *request, HttpResponse *response)
Invoke the handler.
Definition: HttpServer.cpp:489
void setDirectoryListing(bool use)
Set whether or not we will list directories.
Definition: HttpServer.cpp:337
void setFileBufferSize(size_t fileBufferSize)
Set the size of the file buffer. When serving up a file from the file system, we can't afford to read...
Definition: HttpServer.cpp:349
Definition: HttpResponse.h:16