Loading src/http.cpp +17 −1 Original line number Diff line number Diff line Loading @@ -596,11 +596,17 @@ std::vector<char> libhttppp::HttpClient::_h1ReadResponse(const std::string &labe // Store status code and Location for redirect handling _lastStatusCode = res.getStatusCode(); _lastLocation.clear(); _lastContentType.clear(); try { libhttppp::HttpHeader::HeaderData *locHdr = res.getHeaderData("location"); if (locHdr && locHdr->getfirstValue()) _lastLocation = locHdr->getfirstValue()->getvalue(); } catch (...) {} try { libhttppp::HttpHeader::HeaderData *ctHdr = res.getHeaderData("content-type"); if (ctHdr && ctHdr->getfirstValue()) _lastContentType = ctHdr->getfirstValue()->getvalue(); } catch (...) {} size_t body_off = parsed_hsize; Loading Loading @@ -2450,7 +2456,17 @@ const std::vector<char> libhttppp::HttpClient::_h2Request( if (frame_stream == stream_id) { // Decode HPACK response headers auto headers = decoder.decode(payload, frame_len); (void)headers; // We don't need to inspect status for now _lastContentType.clear(); _lastLocation.clear(); 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 (frame_flags & H2C_FLAG_END_STREAM) { got_end_stream = true; } Loading src/http.h +5 −1 Original line number Diff line number Diff line Loading @@ -124,6 +124,9 @@ namespace libhttppp { // Returns the HTTP status code from the last response. int lastStatusCode() const { return _lastStatusCode; } // Returns the Content-Type from the last response. const std::string &lastContentType() const { return _lastContentType; } // Drop the current connection so the next request opens a fresh one. void resetConnection(); Loading Loading @@ -193,9 +196,10 @@ namespace libhttppp { int _sendTimeoutSec = 30; int _vers = 2; // HTTP version preference (0=h1 only, 1=h1+h2, 2=h2 preferred, 3=h3) // Redirect tracking (populated by _h1ReadResponse / _h2Request) // Response tracking (populated by _h1ReadResponse / _h2Request / _h3Request) int _lastStatusCode = 0; std::string _lastLocation; std::string _lastContentType; static constexpr int MAX_REDIRECTS = 5; int _maxRedirects = MAX_REDIRECTS; }; Loading Loading
src/http.cpp +17 −1 Original line number Diff line number Diff line Loading @@ -596,11 +596,17 @@ std::vector<char> libhttppp::HttpClient::_h1ReadResponse(const std::string &labe // Store status code and Location for redirect handling _lastStatusCode = res.getStatusCode(); _lastLocation.clear(); _lastContentType.clear(); try { libhttppp::HttpHeader::HeaderData *locHdr = res.getHeaderData("location"); if (locHdr && locHdr->getfirstValue()) _lastLocation = locHdr->getfirstValue()->getvalue(); } catch (...) {} try { libhttppp::HttpHeader::HeaderData *ctHdr = res.getHeaderData("content-type"); if (ctHdr && ctHdr->getfirstValue()) _lastContentType = ctHdr->getfirstValue()->getvalue(); } catch (...) {} size_t body_off = parsed_hsize; Loading Loading @@ -2450,7 +2456,17 @@ const std::vector<char> libhttppp::HttpClient::_h2Request( if (frame_stream == stream_id) { // Decode HPACK response headers auto headers = decoder.decode(payload, frame_len); (void)headers; // We don't need to inspect status for now _lastContentType.clear(); _lastLocation.clear(); 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 (frame_flags & H2C_FLAG_END_STREAM) { got_end_stream = true; } Loading
src/http.h +5 −1 Original line number Diff line number Diff line Loading @@ -124,6 +124,9 @@ namespace libhttppp { // Returns the HTTP status code from the last response. int lastStatusCode() const { return _lastStatusCode; } // Returns the Content-Type from the last response. const std::string &lastContentType() const { return _lastContentType; } // Drop the current connection so the next request opens a fresh one. void resetConnection(); Loading Loading @@ -193,9 +196,10 @@ namespace libhttppp { int _sendTimeoutSec = 30; int _vers = 2; // HTTP version preference (0=h1 only, 1=h1+h2, 2=h2 preferred, 3=h3) // Redirect tracking (populated by _h1ReadResponse / _h2Request) // Response tracking (populated by _h1ReadResponse / _h2Request / _h3Request) int _lastStatusCode = 0; std::string _lastLocation; std::string _lastContentType; static constexpr int MAX_REDIRECTS = 5; int _maxRedirects = MAX_REDIRECTS; }; Loading