| 159 | } |
| 160 | |
| 161 | bool HttpRequestParser::parseRequestLine() { |
| 162 | auto crlfPos = findCRLF(); |
| 163 | if (!crlfPos.has_value()) { |
| 164 | return false; // Need more data |
| 165 | } |
| 166 | |
| 167 | // Extract request line |
| 168 | fl::string line(reinterpret_cast<const char*>(mBuffer.data()), crlfPos.value()); // ok reinterpret cast |
| 169 | |
| 170 | consume(crlfPos.value() + 2); // +2 for CRLF |
| 171 | |
| 172 | // Parse: "METHOD URI VERSION" |
| 173 | size_t methodEnd = line.find(' '); |
| 174 | if (methodEnd == fl::string::npos) { |
| 175 | return false; // Invalid format |
| 176 | } |
| 177 | |
| 178 | size_t uriEnd = line.find(' ', methodEnd + 1); |
| 179 | if (uriEnd == fl::string::npos) { |
| 180 | return false; // Invalid format |
| 181 | } |
| 182 | |
| 183 | req().method = line.substr(0, methodEnd); |
| 184 | req().uri = line.substr(methodEnd + 1, uriEnd - methodEnd - 1); |
| 185 | req().version = line.substr(uriEnd + 1); |
| 186 | |
| 187 | return true; |
| 188 | } |
| 189 | |
| 190 | bool HttpRequestParser::parseHeaders() { |
| 191 | while (true) { |