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

◆ parseHeaders()

bool fl::HttpResponseParser::parseHeaders ( )
private

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

425 {
426 while (true) {
427 auto crlfPos = findCRLF();
428 if (!crlfPos.has_value()) {
429 return false; // Need more data
430 }
431
432 // Check for empty line (end of headers)
433 if (crlfPos.value() == 0) {
434 consume(2); // Consume final CRLF
435 return true;
436 }
437
438 // Extract header line
439 fl::string line(reinterpret_cast<const char*>(mBuffer.data()), crlfPos.value()); // ok reinterpret cast
440 consume(crlfPos.value() + 2); // +2 for CRLF
441
442 // Parse: "Name: Value"
443 size_t colonPos = line.find(':');
444 if (colonPos == fl::string::npos) {
445 continue; // Skip invalid header
446 }
447
448 fl::string name = http_parser_trim(line.substr(0, colonPos));
449 fl::string value = http_parser_trim(line.substr(colonPos + 1));
450
451 resp().headers[name] = value;
452 }
453}
fl::optional< size_t > findCRLF() const
HttpResponse & resp()
fl::vector< u8 > mBuffer
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:31

References consume(), fl::basic_string::find(), findCRLF(), fl::HttpResponse::headers, mBuffer, fl::string::npos, resp(), 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: