64 : hTTPCompliance(compliance)
65 , socketContext(socketContext)
66 , headerDecoder(socketContext)
67 , trailerDecoder(socketContext) {
148 const std::size_t consumed = headerDecoder.read();
150 if (headerDecoder.isError()) {
151 parseError(headerDecoder.getErrorCode(), headerDecoder.getErrorReason());
152 }
else if (headerDecoder.isComplete()) {
153 headers = std::move(headerDecoder.getHeader());
161 if (headers.contains(
"Content-Length")) {
162 contentLength = std::stoul(headers[
"Content-Length"]);
163 transferEncoding = TransferEncoding::Identity;
164 decoderQueue.emplace_back(
new web::http::decoder::Identity(socketContext, contentLength));
166 if (headers.contains(
"Transfer-Encoding")) {
167 const std::string& encoding = headers[
"Transfer-Encoding"];
169 if (web::http::ciContains(encoding,
"chunked")) {
170 transferEncoding = TransferEncoding::Chunked;
171 decoderQueue.emplace_back(
new web::http::decoder::Chunked(socketContext));
173 if (headers.contains(
"Trailer")) {
174 std::string trailers = headers[
"Trailer"];
176 while (!trailers.empty()) {
177 std::string trailerField;
178 std::tie(trailerField, trailers) = httputils::str_split(trailers,
',');
179 httputils::str_trimm(trailerField);
180 trailerFieldsExpected.insert(trailerField);
181 trailerField.clear();
183 trailerDecoder.setFieldsExpected(trailerFieldsExpected);
186 if (web::http::ciContains(encoding,
"compressed")) {
189 if (web::http::ciContains(encoding,
"deflate")) {
192 if (web::http::ciContains(encoding,
"gzip")) {
196 if (decoderQueue.empty()) {
197 transferEncoding = TransferEncoding::HTTP10;
198 decoderQueue.emplace_back(
new web::http::decoder::HTTP10Response(socketContext));
201 if (headers.contains(
"Content-Encoding")) {
202 const std::string& encoding = headers[
"Content-Encoding"];
204 if (web::http::ciContains(encoding,
"compressed")) {
207 if (web::http::ciContains(encoding,
"deflate")) {
210 if (web::http::ciContains(encoding,
"gzip")) {
213 if (web::http::ciContains(encoding,
"br")) {
220 ContentDecoder* contentDecoder = decoderQueue.front();
222 const std::size_t consumed = contentDecoder->read();
224 if (contentDecoder->isComplete()) {
225 contentDecoder = decoderQueue.back();
227 std::vector<
char> chunk = contentDecoder->getContent();
228 content.insert(content.end(), chunk.begin(), chunk.end());
230 if (transferEncoding == TransferEncoding::Chunked && headers.contains(
"Trailer")) {
235 }
else if (contentDecoder->isError()) {
236 parseError(400,
"Wrong content encoding");
243 const std::size_t consumed = trailerDecoder.read();
245 if (trailerDecoder.isError()) {
246 parseError(trailerDecoder.getErrorCode(), trailerDecoder.getErrorReason());
247 }
else if (trailerDecoder.isComplete()) {
248 web::http::CiStringMap<std::string>&& trailer = trailerDecoder.getHeader();
249 headers.insert(trailer.begin(), trailer.end());