Loading src/http.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -338,6 +338,7 @@ void libhttppp::HttpClient::resetConnection(){ _h2PrefaceSent = false; _h2NextStreamId = 1; _h2Decoder.reset(); _peerWantsClose = false; // getProtocol() alone isn't enough: it's pinned to HTTP3 for the object's // whole lifetime once requested, even after the ctor downgrades _vers on // fallback. Only take the QUIC path when HTTP/3 is still what we want. Loading Loading @@ -634,6 +635,12 @@ std::vector<char> libhttppp::HttpClient::_h1ReadResponse(const std::string &labe if (ctHdr && ctHdr->getfirstValue()) _lastContentType = ctHdr->getfirstValue()->getvalue(); } catch (...) {} try { libhttppp::HttpHeader::HeaderData *connHdr = res.getHeaderData("connection"); if (connHdr && connHdr->getfirstValue() && tolower_copy(connHdr->getfirstValue()->getvalue()) == "close") _peerWantsClose = true; } catch (...) {} size_t body_off = parsed_hsize; Loading Loading @@ -1167,6 +1174,7 @@ libhttppp::HttpResponse libhttppp::HttpClient::GetStream(libhttppp::HttpRequest // request had succeeded. Only treat it as a hard // failure when the peer explicitly never processed // this stream; otherwise keep reading. _peerWantsClose = true; uint32_t last_stream_id = 0; if (frame_len >= 4) { last_stream_id = ((static_cast<uint32_t>(payload[0]) & 0x7f) << 24) Loading Loading @@ -1801,6 +1809,7 @@ size_t libhttppp::HttpClient::_streamReadH2(char *buf, size_t bufsize, bool bloc } break; case H2C_FRAME_GOAWAY: _peerWantsClose = true; _streamH2EndStream = true; break; default: Loading Loading @@ -2771,6 +2780,7 @@ const std::vector<char> libhttppp::HttpClient::_h2Request( // stream, fail loudly instead; otherwise keep reading -- // it may still deliver the remaining frames before closing // (bounded by the deadline/EOF checks around this loop). _peerWantsClose = true; uint32_t last_stream_id = 0; if (frame_len >= 4) { last_stream_id = ((static_cast<uint32_t>(payload[0]) & 0x7f) << 24) Loading src/http.h +12 −0 Original line number Diff line number Diff line Loading @@ -153,6 +153,13 @@ namespace libhttppp { // True while a streaming read is in progress. bool isStreaming() const; // True once the peer has signaled it wants this connection closed // (an HTTP/2 GOAWAY frame, or an HTTP/1.x response's own // "Connection: close" header) -- a caller pooling HttpClient instances // for reuse should check this (and !isStreaming()) before handing an // instance back for a future request instead of closing it. bool wantsClose() const { return _peerWantsClose; } // Wait until upstream socket has data to read (or timeout expires). // timeout_ms: -1 = infinite, 0 = return immediately, >0 = milliseconds // Returns true if readable, false on timeout. Loading Loading @@ -292,6 +299,11 @@ namespace libhttppp { int _sendTimeoutSec = 30; int _vers = 2; // HTTP version preference (0=h1 only, 1=h1+h2, 2=h2 preferred, 3=h3, 4=internal h2-only probe) // Set by _h1ReadResponse (Connection: close) and the H2 GOAWAY handlers // in GetStream/_streamReadH2/_h2Request -- see wantsClose() above. // Reset in resetConnection() since a fresh connection never wants closing. bool _peerWantsClose = false; // Response tracking (populated by _h1ReadResponse / _h2Request / _h3Request) int _lastStatusCode = 0; std::string _lastLocation; Loading Loading
src/http.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -338,6 +338,7 @@ void libhttppp::HttpClient::resetConnection(){ _h2PrefaceSent = false; _h2NextStreamId = 1; _h2Decoder.reset(); _peerWantsClose = false; // getProtocol() alone isn't enough: it's pinned to HTTP3 for the object's // whole lifetime once requested, even after the ctor downgrades _vers on // fallback. Only take the QUIC path when HTTP/3 is still what we want. Loading Loading @@ -634,6 +635,12 @@ std::vector<char> libhttppp::HttpClient::_h1ReadResponse(const std::string &labe if (ctHdr && ctHdr->getfirstValue()) _lastContentType = ctHdr->getfirstValue()->getvalue(); } catch (...) {} try { libhttppp::HttpHeader::HeaderData *connHdr = res.getHeaderData("connection"); if (connHdr && connHdr->getfirstValue() && tolower_copy(connHdr->getfirstValue()->getvalue()) == "close") _peerWantsClose = true; } catch (...) {} size_t body_off = parsed_hsize; Loading Loading @@ -1167,6 +1174,7 @@ libhttppp::HttpResponse libhttppp::HttpClient::GetStream(libhttppp::HttpRequest // request had succeeded. Only treat it as a hard // failure when the peer explicitly never processed // this stream; otherwise keep reading. _peerWantsClose = true; uint32_t last_stream_id = 0; if (frame_len >= 4) { last_stream_id = ((static_cast<uint32_t>(payload[0]) & 0x7f) << 24) Loading Loading @@ -1801,6 +1809,7 @@ size_t libhttppp::HttpClient::_streamReadH2(char *buf, size_t bufsize, bool bloc } break; case H2C_FRAME_GOAWAY: _peerWantsClose = true; _streamH2EndStream = true; break; default: Loading Loading @@ -2771,6 +2780,7 @@ const std::vector<char> libhttppp::HttpClient::_h2Request( // stream, fail loudly instead; otherwise keep reading -- // it may still deliver the remaining frames before closing // (bounded by the deadline/EOF checks around this loop). _peerWantsClose = true; uint32_t last_stream_id = 0; if (frame_len >= 4) { last_stream_id = ((static_cast<uint32_t>(payload[0]) & 0x7f) << 24) Loading
src/http.h +12 −0 Original line number Diff line number Diff line Loading @@ -153,6 +153,13 @@ namespace libhttppp { // True while a streaming read is in progress. bool isStreaming() const; // True once the peer has signaled it wants this connection closed // (an HTTP/2 GOAWAY frame, or an HTTP/1.x response's own // "Connection: close" header) -- a caller pooling HttpClient instances // for reuse should check this (and !isStreaming()) before handing an // instance back for a future request instead of closing it. bool wantsClose() const { return _peerWantsClose; } // Wait until upstream socket has data to read (or timeout expires). // timeout_ms: -1 = infinite, 0 = return immediately, >0 = milliseconds // Returns true if readable, false on timeout. Loading Loading @@ -292,6 +299,11 @@ namespace libhttppp { int _sendTimeoutSec = 30; int _vers = 2; // HTTP version preference (0=h1 only, 1=h1+h2, 2=h2 preferred, 3=h3, 4=internal h2-only probe) // Set by _h1ReadResponse (Connection: close) and the H2 GOAWAY handlers // in GetStream/_streamReadH2/_h2Request -- see wantsClose() above. // Reset in resetConnection() since a fresh connection never wants closing. bool _peerWantsClose = false; // Response tracking (populated by _h1ReadResponse / _h2Request / _h3Request) int _lastStatusCode = 0; std::string _lastLocation; Loading