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

◆ parseRequestLine()

bool fl::HttpRequestParser::parseRequestLine ( )
private

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

161 {
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}
HttpRequest & req()
Definition http_parser.h:81
fl::optional< size_t > findCRLF() const
fl::vector< u8 > mBuffer
Definition http_parser.h:75
string substr(fl::size start, fl::size length) const FL_NOEXCEPT
static constexpr fl::size npos
Definition string.h:195
fl::string method
Definition http_parser.h:19
fl::string uri
Definition http_parser.h:20
fl::string version
Definition http_parser.h:21

References consume(), fl::basic_string::find(), findCRLF(), mBuffer, fl::HttpRequest::method, fl::string::npos, req(), fl::string::substr(), fl::HttpRequest::uri, and fl::HttpRequest::version.

Referenced by feed().

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