Commit 3ca63e99 authored by jan.koester's avatar jan.koester
Browse files

maxtriex added

parent 73819fb2
Loading
Loading
Loading
Loading
+168 −140
Original line number Diff line number Diff line
@@ -2133,8 +2133,10 @@ const std::vector<char> libhttppp::HttpClient::_h2Request(
    }
  }

const std::vector<char> libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq)
const std::vector<char> libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq, size_t maxTries)
{
    size_t tries = 0;
    for (;;) {
        try {
            // Reuse existing connection if possible (avoid expensive TLS handshakes)
            _ensureConnected();
@@ -2180,15 +2182,22 @@ const std::vector<char> libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq)
            }

        } catch (netplus::NetException &e) {
            ++tries;
            if (maxTries != 0 && tries >= maxTries) {
                libhttppp::HTTPException ee;
                ee[libhttppp::HTTPException::Error] << e.what();
                throw ee;
            }
            resetConnection();
        }
    }
}

const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq,
                                                    const std::vector<char> &post)
                                                    const std::vector<char> &post, size_t maxTries)
{
    size_t tries = 0;
    for (;;) {
        try {
            // Reuse existing connection if possible
            _ensureConnected();
@@ -2232,14 +2241,21 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq
            return _h1ReadResponse("POST");

        } catch (netplus::NetException &e) {
            ++tries;
            if (maxTries != 0 && tries >= maxTries) {
                libhttppp::HTTPException ee;
                ee[libhttppp::HTTPException::Error] << e.what();
                throw ee;
            }
            resetConnection();
        }
    }
}

const std::vector<char> libhttppp::HttpClient::Delete(libhttppp::HttpRequest &nreq)
const std::vector<char> libhttppp::HttpClient::Delete(libhttppp::HttpRequest &nreq, size_t maxTries)
{
    size_t tries = 0;
    for (;;) {
        try {
            // Reuse existing connection if possible
            _ensureConnected();
@@ -2276,15 +2292,22 @@ const std::vector<char> libhttppp::HttpClient::Delete(libhttppp::HttpRequest &nr
            return _h1ReadResponse("DELETE");

        } catch (netplus::NetException &e) {
            ++tries;
            if (maxTries != 0 && tries >= maxTries) {
                libhttppp::HTTPException ee;
                ee[libhttppp::HTTPException::Error] << e.what();
                throw ee;
            }
            resetConnection();
        }
    }
}

const std::vector<char> libhttppp::HttpClient::Put(libhttppp::HttpRequest &nreq,
                                                   const std::vector<char> &put)
                                                   const std::vector<char> &put, size_t maxTries)
{
    size_t tries = 0;
    for (;;) {
        try {
            // Reuse existing connection if possible
            _ensureConnected();
@@ -2328,10 +2351,15 @@ const std::vector<char> libhttppp::HttpClient::Put(libhttppp::HttpRequest &nreq,
            return _h1ReadResponse("PUT");

        } catch (netplus::NetException &e) {
            ++tries;
            if (maxTries != 0 && tries >= maxTries) {
                libhttppp::HTTPException ee;
                ee[libhttppp::HTTPException::Error] << e.what();
                throw ee;
            }
            resetConnection();
        }
    }
}

int libhttppp::HttpClient::readchunk(const char *data, int datasize, int &pos)
+4 −4
Original line number Diff line number Diff line
@@ -89,10 +89,10 @@ namespace libhttppp {
      HttpClient( const HttpUrl &desturl);
      ~HttpClient()=default;
      void reconnect();
      const std::vector<char> Get(HttpRequest &nreq);
      const std::vector<char> Post(HttpRequest &nreq,const std::vector<char> &post);
      const std::vector<char> Put(HttpRequest &nreq,const std::vector<char> &put);
      const std::vector<char> Delete(HttpRequest &nreq);
      const std::vector<char> Get(HttpRequest &nreq, size_t maxTries=0);
      const std::vector<char> Post(HttpRequest &nreq,const std::vector<char> &post, size_t maxTries=0);
      const std::vector<char> Put(HttpRequest &nreq,const std::vector<char> &put, size_t maxTries=0);
      const std::vector<char> Delete(HttpRequest &nreq, size_t maxTries=0);

      // Streaming API: send request, return parsed response headers only.
      // After this call, use readBodyChunk() to read body data incrementally.