Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
MultipartParser.h
Go to the documentation of this file.
1
17#ifndef MULTIPART_PARSER_HPP
18#define MULTIPART_PARSER_HPP
19#pragma once
20
21#include <string>
22#include <unordered_map>
23#include "http/HttpRequest.h"
24#include "network/Tcp.h"
25
33
44{
45public:
53
63 bool handleMultipart(HttpRequest& req, HttpResponse& res); // external interface for handling multipart uploads
64
69 void setBoundaryFromContentType(const std::string& contentType);
70
71private:
73 std::string boundary;
74 std::string filename;
75 std::string leftoverData;
76 std::string buffer;
77
78
80
86 bool extractFilename(const std::string &contentDisposition);
87
93 bool processFileData(const std::string &fileData);
94
100 bool handleChunk(std::string &chunkData);
101
109 int appendFileToSD(const char *filename, const char *data, size_t size);
110
116 int file_exists(const std::string& filename);
117
123 int findDataStart(std::string &currentData);
124
130 bool handleFinalBoundary(std::string &fileData);
131
137 void sendHttpResponse(int statusCode, const std::string &message);
138};
139
140#endif // MULTIPART_PARSER_HPP
Defines the HttpRequest class for handling HTTP requests: headers, method, path, query string,...
@ COMPLETE
@ FOUND_BOUNDARY
@ FOUND_DATA_START
@ SEARCHING_FOR_BOUNDARY
General-purpose TCP socket abstraction with optional TLS support for both client and server use.
Forward declaration for potential routing needs.
Definition HttpRequest.h:32
Represents an HTTP response object.
Parses and processes multipart/form-data uploads over HTTP.
int appendFileToSD(const char *filename, const char *data, size_t size)
Append file data to storage (e.g., SD card).
std::string leftoverData
std::string filename
Tcp * tcp
The client TCP connection.
void sendHttpResponse(int statusCode, const std::string &message)
Send a simple HTTP response to the client.
bool processFileData(const std::string &fileData)
Append a chunk of file data to the output file.
void setBoundaryFromContentType(const std::string &contentType)
sets the boundary from the Content-Type header.
std::string buffer
MultipartParser()
Construct a new Multipart Parser object.
bool handleFinalBoundary(std::string &fileData)
Detect and handle the final multipart boundary.
int findDataStart(std::string &currentData)
Find the start of the file content in a chunk (after headers).
std::string boundary
bool handleChunk(std::string &chunkData)
Handle an incoming chunk of multipart data.
bool handleMultipart(HttpRequest &req, HttpResponse &res)
Begin processing the multipart upload from the socket.
int file_exists(const std::string &filename)
Check if a file already exists in storage.
static State currentState
bool extractFilename(const std::string &contentDisposition)
Extract the filename from a Content-Disposition header.
General-purpose TCP socket wrapper with optional TLS support via mbedTLS (altcp).
Definition Tcp.h:39