| 188 | } |
| 189 | |
| 190 | bool HttpRequestParser::parseHeaders() { |
| 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 | } |
| 219 | |
| 220 | void HttpRequestParser::parseBody() { |
| 221 | if (mIsChunked) { |