FastLED 3.9.15
Loading...
Searching...
No Matches

◆ parseHeaders()

bool fl::HttpRequestParser::parseHeaders ( )
private

Definition at line 190 of file http_parser.cpp.hpp.

190 {
191 while (true) {
192 auto crlfPos = findCRLF();
193 if (!crlfPos.has_value()) {
194 return false; // Need more data
195 }
196
197 // Check for empty line (end of headers)
198 if (crlfPos.value() == 0) {
199 consume(2); // Consume final CRLF
200 return true;
201 }
202
203 // Extract header line
204 fl::string line(reinterpret_cast<const char*>(mBuffer.data()), crlfPos.value()); // ok reinterpret cast
205 consume(crlfPos.value() + 2); // +2 for CRLF
206
207 // Parse: "Name: Value"
208 size_t colonPos = line.find(':');
209 if (colonPos == fl::string::npos) {
210 continue; // Skip invalid header
211 }
212
213 fl::string name = http_parser_trim(line.substr(0, colonPos));
214 fl::string value = http_parser_trim(line.substr(colonPos + 1));
215
216 req().headers[name] = value;
217 }
218}
HttpRequest & req()
Definition http_parser.h:81
fl::optional< size_t > findCRLF() const
fl::vector< u8 > mBuffer
Definition http_parser.h:75
static constexpr fl::size npos
Definition string.h:195
fl::string http_parser_trim(const fl::string &str)
constexpr int type_rank< T >::value
fl::flat_map< fl::string, fl::string, fl::StringFastLess > headers
Definition http_parser.h:22

References consume(), fl::basic_string::find(), findCRLF(), fl::HttpRequest::headers, mBuffer, fl::string::npos, req(), fl::string::substr(), and fl::type_rank< T >::value.

Referenced by feed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: