Commit 1449b0ee authored by jan.koester's avatar jan.koester
Browse files

tetst

parent de1274ca
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -583,6 +583,15 @@ std::vector<char> libhttppp::HttpClient::_h1ReadResponse(const std::string &labe
        throw he;
    }

    // Store status code and Location for redirect handling
    _lastStatusCode = res.getStatusCode();
    _lastLocation.clear();
    try {
        libhttppp::HttpHeader::HeaderData *locHdr = res.getHeaderData("location");
        if (locHdr && locHdr->getfirstValue())
            _lastLocation = locHdr->getfirstValue()->getvalue();
    } catch (...) {}

    size_t body_off = parsed_hsize;

    // 3) Determine transfer mode
@@ -2735,6 +2744,7 @@ const std::vector<char> libhttppp::HttpClient::_h2Request(
const std::vector<char> libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq, size_t maxTries)
{
    size_t tries = 0;
    int redirects = 0;
    for (;;) {
        try {
            // Reuse existing connection if possible (avoid expensive TLS handshakes)
@@ -2774,6 +2784,23 @@ const std::vector<char> libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq,
                // Read and parse response using shared helper
                std::vector<char> ret = _h1ReadResponse("GET");

                // Handle redirects (301, 302, 303, 307, 308)
                if (_lastStatusCode >= 301 && _lastStatusCode <= 308
                    && _lastStatusCode != 304 && _lastStatusCode != 305
                    && !_lastLocation.empty() && redirects < MAX_REDIRECTS)
                {
                    ++redirects;
                    // Update request URL for relative or absolute redirect
                    if (_lastLocation.find("://") != std::string::npos) {
                        _url = HttpUrl(_lastLocation);
                        resetConnection();
                    }
                    nreq.setRequestURL(_lastLocation.find("://") != std::string::npos
                        ? _url.getPath() : _lastLocation);
                    // 303: always GET; 307/308: preserve method (already GET)
                    continue;
                }

                return ret;
            }

+5 −0
Original line number Diff line number Diff line
@@ -182,6 +182,11 @@ namespace libhttppp {
      netplus::x509cert _cert;
      int _recvTimeoutSec = 60;
      int _sendTimeoutSec = 30;

      // Redirect tracking (populated by _h1ReadResponse / _h2Request)
      int _lastStatusCode = 0;
      std::string _lastLocation;
      static constexpr int MAX_REDIRECTS = 5;
  };