Loading src/http.cpp +46 −41 Original line number Diff line number Diff line Loading @@ -2456,26 +2456,26 @@ const std::vector<char> libhttppp::HttpClient::_h2Request( case H2C_FRAME_HEADERS: { if (frame_stream == stream_id) { // Decode HPACK response headers auto headers = decoder.decode(payload, frame_len); _lastContentType.clear(); _lastLocation.clear(); // Build synthetic HTTP/1.1 response for HttpResponse::parse() std::string status_val = "200"; for (const auto &h : headers) if (h.name == ":status") status_val = h.value; std::string synth = "HTTP/1.1 " + status_val + "\r\n"; for (const auto &h : headers) if (!h.name.empty() && h.name[0] != ':') synth += h.name + ": " + h.value + "\r\n"; synth += "\r\n"; _lastResponse = std::make_unique<HttpResponse>(); for (const auto &h : headers) { if (h.name == ":status") { try { _lastStatusCode = std::stoi(h.value); } catch (...) {} } else if (h.name == "content-type") { _lastContentType = h.value; } else if (h.name == "location") { _lastLocation = h.value; } if (!h.name.empty() && h.name[0] != ':') { _lastResponse->setHeaderData(h.name)->push_back(h.value); } } _lastResponse->setState(std::to_string(_lastStatusCode)); if (!_lastContentType.empty()) _lastResponse->setContentType(_lastContentType); _lastResponse->parse(synth.c_str(), synth.size()); _lastStatusCode = _lastResponse->getStatusCode(); _lastContentType = _lastResponse->getContentType(); _lastLocation.clear(); try { auto *loc = _lastResponse->getHeaderData("location"); if (loc && loc->getfirstValue()) _lastLocation = loc->getfirstValue()->getvalue(); } catch (...) {} if (frame_flags & H2C_FLAG_END_STREAM) { got_end_stream = true; } Loading Loading @@ -2696,30 +2696,35 @@ const std::vector<char> libhttppp::HttpClient::_h2Request( pos = frame_start; break; } else if (frame_type == 0x01) { auto decoded = qpack::Decoder::decode(raw.data() + pos, frame_len); _lastContentType.clear(); _lastLocation.clear(); // Build synthetic HTTP/1.1 response for HttpResponse::parse() std::string status_val = "200"; for (const auto &h : decoded) if (h.name == ":status") status_val = h.value; std::string synth = "HTTP/1.1 " + status_val + "\r\n"; for (const auto &h : decoded) if (!h.name.empty() && h.name[0] != ':') synth += h.name + ": " + h.value + "\r\n"; synth += "\r\n"; _lastResponse = std::make_unique<HttpResponse>(); for (const auto &h : decoded) { if (h.name == ":status") { try { status_code = std::stoi(h.value); _lastStatusCode = status_code; } catch (...) { status_code = 0; } } else if (h.name == "location") { location = h.value; _lastLocation = h.value; } else if (h.name == "content-length") { _lastResponse->parse(synth.c_str(), synth.size()); _lastStatusCode = _lastResponse->getStatusCode(); status_code = _lastStatusCode; _lastContentType = _lastResponse->getContentType(); _lastLocation.clear(); try { expected_body = static_cast<size_t>(std::stoul(h.value)); body.reserve(expected_body); } catch (...) {} } else if (h.name == "content-type") { _lastContentType = h.value; } if (!h.name.empty() && h.name[0] != ':') { _lastResponse->setHeaderData(h.name)->push_back(h.value); auto *loc = _lastResponse->getHeaderData("location"); if (loc && loc->getfirstValue()) { _lastLocation = loc->getfirstValue()->getvalue(); location = _lastLocation; } } catch (...) {} try { size_t cl = _lastResponse->getContentLength(); if (cl > 0) { expected_body = cl; body.reserve(expected_body); } _lastResponse->setState(std::to_string(_lastStatusCode)); if (!_lastContentType.empty()) _lastResponse->setContentType(_lastContentType); } catch (...) {} got_headers = true; pos += frame_len; } else { Loading Loading
src/http.cpp +46 −41 Original line number Diff line number Diff line Loading @@ -2456,26 +2456,26 @@ const std::vector<char> libhttppp::HttpClient::_h2Request( case H2C_FRAME_HEADERS: { if (frame_stream == stream_id) { // Decode HPACK response headers auto headers = decoder.decode(payload, frame_len); _lastContentType.clear(); _lastLocation.clear(); // Build synthetic HTTP/1.1 response for HttpResponse::parse() std::string status_val = "200"; for (const auto &h : headers) if (h.name == ":status") status_val = h.value; std::string synth = "HTTP/1.1 " + status_val + "\r\n"; for (const auto &h : headers) if (!h.name.empty() && h.name[0] != ':') synth += h.name + ": " + h.value + "\r\n"; synth += "\r\n"; _lastResponse = std::make_unique<HttpResponse>(); for (const auto &h : headers) { if (h.name == ":status") { try { _lastStatusCode = std::stoi(h.value); } catch (...) {} } else if (h.name == "content-type") { _lastContentType = h.value; } else if (h.name == "location") { _lastLocation = h.value; } if (!h.name.empty() && h.name[0] != ':') { _lastResponse->setHeaderData(h.name)->push_back(h.value); } } _lastResponse->setState(std::to_string(_lastStatusCode)); if (!_lastContentType.empty()) _lastResponse->setContentType(_lastContentType); _lastResponse->parse(synth.c_str(), synth.size()); _lastStatusCode = _lastResponse->getStatusCode(); _lastContentType = _lastResponse->getContentType(); _lastLocation.clear(); try { auto *loc = _lastResponse->getHeaderData("location"); if (loc && loc->getfirstValue()) _lastLocation = loc->getfirstValue()->getvalue(); } catch (...) {} if (frame_flags & H2C_FLAG_END_STREAM) { got_end_stream = true; } Loading Loading @@ -2696,30 +2696,35 @@ const std::vector<char> libhttppp::HttpClient::_h2Request( pos = frame_start; break; } else if (frame_type == 0x01) { auto decoded = qpack::Decoder::decode(raw.data() + pos, frame_len); _lastContentType.clear(); _lastLocation.clear(); // Build synthetic HTTP/1.1 response for HttpResponse::parse() std::string status_val = "200"; for (const auto &h : decoded) if (h.name == ":status") status_val = h.value; std::string synth = "HTTP/1.1 " + status_val + "\r\n"; for (const auto &h : decoded) if (!h.name.empty() && h.name[0] != ':') synth += h.name + ": " + h.value + "\r\n"; synth += "\r\n"; _lastResponse = std::make_unique<HttpResponse>(); for (const auto &h : decoded) { if (h.name == ":status") { try { status_code = std::stoi(h.value); _lastStatusCode = status_code; } catch (...) { status_code = 0; } } else if (h.name == "location") { location = h.value; _lastLocation = h.value; } else if (h.name == "content-length") { _lastResponse->parse(synth.c_str(), synth.size()); _lastStatusCode = _lastResponse->getStatusCode(); status_code = _lastStatusCode; _lastContentType = _lastResponse->getContentType(); _lastLocation.clear(); try { expected_body = static_cast<size_t>(std::stoul(h.value)); body.reserve(expected_body); } catch (...) {} } else if (h.name == "content-type") { _lastContentType = h.value; } if (!h.name.empty() && h.name[0] != ':') { _lastResponse->setHeaderData(h.name)->push_back(h.value); auto *loc = _lastResponse->getHeaderData("location"); if (loc && loc->getfirstValue()) { _lastLocation = loc->getfirstValue()->getvalue(); location = _lastLocation; } } catch (...) {} try { size_t cl = _lastResponse->getContentLength(); if (cl > 0) { expected_body = cl; body.reserve(expected_body); } _lastResponse->setState(std::to_string(_lastStatusCode)); if (!_lastContentType.empty()) _lastResponse->setContentType(_lastContentType); } catch (...) {} got_headers = true; pos += frame_len; } else { Loading