| 387 | } |
| 388 | |
| 389 | bool HttpResponseParser::parseStatusLine() { |
| 390 | auto crlfPos = findCRLF(); |
| 391 | if (!crlfPos.has_value()) { |
| 392 | return false; // Need more data |
| 393 | } |
| 394 | |
| 395 | // Extract status line |
| 396 | fl::string line(reinterpret_cast<const char*>(mBuffer.data()), crlfPos.value()); // ok reinterpret cast |
| 397 | consume(crlfPos.value() + 2); // +2 for CRLF |
| 398 | |
| 399 | // Parse: "VERSION STATUS_CODE REASON_PHRASE" |
| 400 | size_t versionEnd = line.find(' '); |
| 401 | if (versionEnd == fl::string::npos) { |
| 402 | return false; // Invalid format |
| 403 | } |
| 404 | |
| 405 | size_t statusEnd = line.find(' ', versionEnd + 1); |
| 406 | if (statusEnd == fl::string::npos) { |
| 407 | // No reason phrase (optional in HTTP/1.1) |
| 408 | statusEnd = line.size(); |
| 409 | } |
| 410 | |
| 411 | resp().version = line.substr(0, versionEnd); |
| 412 | fl::string statusStr = line.substr(versionEnd + 1, statusEnd - versionEnd - 1); |
| 413 | |
| 414 | if (!parseInt(statusStr, resp().statusCode)) { |
| 415 | return false; // Invalid status code |
| 416 | } |
| 417 | |
| 418 | if (statusEnd < line.size()) { |
| 419 | resp().reasonPhrase = line.substr(statusEnd + 1); |
| 420 | } |
| 421 | |
| 422 | return true; |
| 423 | } |
| 424 | |
| 425 | bool HttpResponseParser::parseHeaders() { |
| 426 | while (true) { |