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

◆ feed()

void fl::HttpResponseParser::feed ( fl::span< const u8 > data)

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

300 {
301 mBuffer.insert(mBuffer.end(), data.begin(), data.end());
302
303 // State machine: parse incrementally
304 bool progress = true;
305 while (progress && mState != COMPLETE) {
306 progress = false;
307
308 switch (mState) {
309 case READ_STATUS_LINE:
310
311 if (parseStatusLine()) {
312
314 progress = true;
315 }
316 break;
317
318 case READ_HEADERS:
319
320 if (parseHeaders()) {
321
322 // Check if body is expected
323 auto contentLength = getHeader("Content-Length");
324 auto transferEncoding = getHeader("Transfer-Encoding");
325
326 if (transferEncoding.has_value() &&
327 toLower(transferEncoding.value()).find("chunked") != fl::string::npos) {
328 mIsChunked = true;
330 } else if (contentLength.has_value()) {
331 int contentLengthInt = 0;
332 if (parseInt(contentLength.value(), contentLengthInt)) {
333 mContentLength = static_cast<size_t>(contentLengthInt);
335 } else {
336 // Invalid Content-Length, skip to complete
338 }
339 } else {
340 // No body
342 }
343 progress = true;
344 }
345 break;
346
347 case READ_BODY:
348
349 parseBody();
350 // parseBody() will set mState to COMPLETE when done
351 // Continue processing if state changed to COMPLETE
352 if (mState == COMPLETE) {
353
354 progress = true;
355 }
356 break;
357
358 case COMPLETE:
359 // Nothing to do
360 break;
361 }
362 }
363}
fl::vector< u8 > mBuffer
fl::optional< fl::string > getHeader(const char *name) const
fl::size find(const char &value) const FL_NOEXCEPT
iterator begin() FL_NOEXCEPT
Definition span.h:440
iterator end() FL_NOEXCEPT
Definition span.h:444
static constexpr fl::size npos
Definition string.h:195
fl::string toLower(const fl::string &str)
int parseInt(const char *str, fl::size len)
Parse an integer from a character buffer.

References HttpResponseParser(), COMPLETE, feed(), fl::basic_string::find(), getHeader(), mBuffer, mContentLength, mIsChunked, mState, fl::string::npos, parseBody(), parseHeaders(), fl::parseInt(), parseStatusLine(), READ_BODY, READ_HEADERS, and READ_STATUS_LINE.

Referenced by ~HttpResponseParser(), and feed().

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