Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
HttpFileserver.h
Go to the documentation of this file.
1
12#ifndef HTTP_FILE_SERVER_H
13#define HTTP_FILE_SERVER_H
14#pragma once
15
16#include <string>
17#include <vector>
18
19#include "http/HttpRequest.h"
20#include "http/HttpResponse.h"
22#include "http/RouteTypes.h"
23
28{
29public:
34
39 bool init();
40
45 bool listDirectory(const std::string& path, std::vector<FileInfo>& out);
46
53 bool serveFile(HttpResponse &res, const char *uri);
54
58 bool mounted = false;
59
60private:
62};
63
68{
69public:
74
81 void handle_static_request(HttpRequest &req, HttpResponse &res, const RouteMatch &match);
82
89 void handle_list_directory(HttpRequest &req, HttpResponse &res, const RouteMatch &match);
90
96 std::string getMimeType(const std::string &filePath);
97
98private:
100};
101
102#endif // HTTP_FILE_SERVER_H
Defines the HttpRequest class for handling HTTP requests: headers, method, path, query string,...
HTTP HttpResponse class for managing status, headers, body, and streaming support.
Abstract interface for file and directory storage backends.
Helper class for accessing the file system and serving file content.
FileHandler()
Construct a new FileHandler object.
bool mounted
Flag indicating whether storage is mounted.
bool serveFile(HttpResponse &res, const char *uri)
Serve a file to the client via the HttpResponse object.
StorageManager * storageManager
bool listDirectory(const std::string &path, std::vector< FileInfo > &out)
Return a list of a given directory.
bool init()
Initialize and mount the storage (e.g., SD card).
HTTP-level controller for serving static files and directory listings.
std::string getMimeType(const std::string &filePath)
Get the MIME type based on the file extension.
void handle_list_directory(HttpRequest &req, HttpResponse &res, const RouteMatch &match)
Handle requests to list directory contents.
void handle_static_request(HttpRequest &req, HttpResponse &res, const RouteMatch &match)
Handle requests for static file content.
FileHandler fileHandler
HttpFileserver()
Construct a new HttpFileserver object.
Forward declaration for potential routing needs.
Definition HttpRequest.h:32
Represents an HTTP response object.
Abstract base class for storage access and file operations.
Represents a match of a route against an incoming HTTP request.
Definition RouteTypes.h:18