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

◆ feed()

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

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

72 {
73 mBuffer.insert(mBuffer.end(), data.begin(), data.end());
74
75 // State machine: parse incrementally
76 bool progress = true;
77 while (progress && mState != COMPLETE) {
78 progress = false;
79
80 switch (mState) {
82
83 if (parseRequestLine()) {
84
86 progress = true;
87 }
88 break;
89
90 case READ_HEADERS:
91
92 if (parseHeaders()) {
93
94 // Check if body is expected
95 auto contentLength = getHeader("Content-Length");
96 auto transferEncoding = getHeader("Transfer-Encoding");
97
98 if (transferEncoding.has_value() &&
99 toLower(transferEncoding.value()).find("chunked") != fl::string::npos) {
100 mIsChunked = true;
102 } else if (contentLength.has_value()) {
103 int contentLengthInt = 0;
104 if (parseInt(contentLength.value(), contentLengthInt)) {
105 mContentLength = static_cast<size_t>(contentLengthInt);
107 } else {
108 // Invalid Content-Length, skip to complete
110 }
111 } else {
112 // No body
114 }
115 progress = true;
116 }
117 break;
118
119 case READ_BODY:
120
121 parseBody();
122 // parseBody() will set mState to COMPLETE when done
123 // Continue processing if state changed to COMPLETE
124 if (mState == COMPLETE) {
125
126 progress = true;
127 }
128 break;
129
130 case COMPLETE:
131 // Nothing to do
132 break;
133 }
134 }
135}
fl::optional< fl::string > getHeader(const char *name) const
fl::vector< u8 > mBuffer
Definition http_parser.h:75
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 HttpRequestParser(), COMPLETE, feed(), fl::basic_string::find(), getHeader(), mBuffer, mContentLength, mIsChunked, mState, fl::string::npos, parseBody(), parseHeaders(), fl::parseInt(), parseRequestLine(), READ_BODY, READ_HEADERS, and READ_REQUEST_LINE.

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

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