42 : hTTPCompliance(compliance)
43 , socketContext(socketContext)
44 , headerDecoder(socketContext)
45 , trailerDecoder(socketContext) {
126 const std::size_t consumed = headerDecoder.read();
128 if (headerDecoder.isError()) {
129 parseError(headerDecoder.getErrorCode(), headerDecoder.getErrorReason());
130 }
else if (headerDecoder.isComplete()) {
131 headers = std::move(headerDecoder.getHeader());
139 if (headers.contains(
"Content-Length")) {
140 contentLength = std::stoul(headers[
"Content-Length"]);
141 transferEncoding = TransferEncoding::Identity;
142 decoderQueue.emplace_back(
new web::http::decoder::Identity(socketContext, contentLength));
144 if (headers.contains(
"Transfer-Encoding")) {
145 const std::string& encoding = headers[
"Transfer-Encoding"];
147 if (web::http::ciContains(encoding,
"chunked")) {
148 transferEncoding = TransferEncoding::Chunked;
149 decoderQueue.emplace_back(
new web::http::decoder::Chunked(socketContext));
151 if (headers.contains(
"Trailer")) {
152 std::string trailers = headers[
"Trailer"];
154 while (!trailers.empty()) {
155 std::string trailerField;
156 std::tie(trailerField, trailers) = httputils::str_split(trailers,
',');
157 httputils::str_trimm(trailerField);
158 trailerFieldsExpected.insert(trailerField);
159 trailerField.clear();
161 trailerDecoder.setFieldsExpected(trailerFieldsExpected);
164 if (web::http::ciContains(encoding,
"compressed")) {
167 if (web::http::ciContains(encoding,
"deflate")) {
170 if (web::http::ciContains(encoding,
"gzip")) {
174 if (decoderQueue.empty()) {
175 transferEncoding = TransferEncoding::HTTP10;
176 decoderQueue.emplace_back(
new web::http::decoder::HTTP10Response(socketContext));
179 if (headers.contains(
"Content-Encoding")) {
180 const std::string& encoding = headers[
"Content-Encoding"];
182 if (web::http::ciContains(encoding,
"compressed")) {
185 if (web::http::ciContains(encoding,
"deflate")) {
188 if (web::http::ciContains(encoding,
"gzip")) {
191 if (web::http::ciContains(encoding,
"br")) {
198 ContentDecoder* contentDecoder = decoderQueue.front();
200 const std::size_t consumed = contentDecoder->read();
202 if (contentDecoder->isComplete()) {
203 contentDecoder = decoderQueue.back();
205 std::vector<
char> chunk = contentDecoder->getContent();
206 content.insert(content.end(), chunk.begin(), chunk.end());
208 if (transferEncoding == TransferEncoding::Chunked && headers.contains(
"Trailer")) {
213 }
else if (contentDecoder->isError()) {
214 parseError(400,
"Wrong content encoding");
221 const std::size_t consumed = trailerDecoder.read();
223 if (trailerDecoder.isError()) {
224 parseError(trailerDecoder.getErrorCode(), trailerDecoder.getErrorReason());
225 }
else if (trailerDecoder.isComplete()) {
226 web::http::CiStringMap<std::string>&& trailer = trailerDecoder.getHeader();
227 headers.insert(trailer.begin(), trailer.end());