Loading src/http.cpp +38 −3 Original line number Diff line number Diff line Loading @@ -2836,6 +2836,7 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq { size_t tries = 0; int redirects = 0; bool convertedToGet = false; for (;;) { try { // Reuse existing connection if possible Loading @@ -2845,10 +2846,44 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq host << _url.getHost() << ":" << _url.getPort(); nreq.setHeaderData("host")->push_back(host.str()); if (!convertedToGet) nreq.setRequestType(POSTREQUEST); if (nreq.getRequestURL().empty()) nreq.setRequestURL(_url.getPath()); if (convertedToGet) { // 303 redirect: switch to GET without body (RFC 7231 §6.4.4) nreq.setRequestType(GETREQUEST); if (nreq.getRequestVersion().empty()) nreq.setRequestVersion(HTTPVERSION(1.1)); std::string header; nreq.printHeader(header); if (!_cltsock || _cltsock->fd() < 0) resetConnection(); _sendAll(header); auto ret = _h1ReadResponse("GET"); // Handle further redirects if (_lastStatusCode >= 301 && _lastStatusCode <= 308 && _lastStatusCode != 304 && _lastStatusCode != 305 && !_lastLocation.empty() && redirects < MAX_REDIRECTS) { ++redirects; if (_lastLocation.find("://") != std::string::npos) { _url = HttpUrl(_lastLocation); resetConnection(); } nreq.setRequestURL(_lastLocation.find("://") != std::string::npos ? _url.getPath() : _lastLocation); continue; } return ret; } nreq.setHeaderData("content-length")->push_back(std::to_string(post.size())); if (dynamic_cast<netplus::quic*>(_cltsock.get())) { Loading Loading @@ -2891,9 +2926,9 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq } nreq.setRequestURL(_lastLocation.find("://") != std::string::npos ? _url.getPath() : _lastLocation); // 303: change to GET (RFC 7231). 307/308: preserve POST. // 303: change to GET without body (RFC 7231 §6.4.4). 307/308: preserve POST. if (_lastStatusCode == 303) { nreq.setRequestType(GETREQUEST); convertedToGet = true; } continue; } Loading Loading
src/http.cpp +38 −3 Original line number Diff line number Diff line Loading @@ -2836,6 +2836,7 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq { size_t tries = 0; int redirects = 0; bool convertedToGet = false; for (;;) { try { // Reuse existing connection if possible Loading @@ -2845,10 +2846,44 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq host << _url.getHost() << ":" << _url.getPort(); nreq.setHeaderData("host")->push_back(host.str()); if (!convertedToGet) nreq.setRequestType(POSTREQUEST); if (nreq.getRequestURL().empty()) nreq.setRequestURL(_url.getPath()); if (convertedToGet) { // 303 redirect: switch to GET without body (RFC 7231 §6.4.4) nreq.setRequestType(GETREQUEST); if (nreq.getRequestVersion().empty()) nreq.setRequestVersion(HTTPVERSION(1.1)); std::string header; nreq.printHeader(header); if (!_cltsock || _cltsock->fd() < 0) resetConnection(); _sendAll(header); auto ret = _h1ReadResponse("GET"); // Handle further redirects if (_lastStatusCode >= 301 && _lastStatusCode <= 308 && _lastStatusCode != 304 && _lastStatusCode != 305 && !_lastLocation.empty() && redirects < MAX_REDIRECTS) { ++redirects; if (_lastLocation.find("://") != std::string::npos) { _url = HttpUrl(_lastLocation); resetConnection(); } nreq.setRequestURL(_lastLocation.find("://") != std::string::npos ? _url.getPath() : _lastLocation); continue; } return ret; } nreq.setHeaderData("content-length")->push_back(std::to_string(post.size())); if (dynamic_cast<netplus::quic*>(_cltsock.get())) { Loading Loading @@ -2891,9 +2926,9 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq } nreq.setRequestURL(_lastLocation.find("://") != std::string::npos ? _url.getPath() : _lastLocation); // 303: change to GET (RFC 7231). 307/308: preserve POST. // 303: change to GET without body (RFC 7231 §6.4.4). 307/308: preserve POST. if (_lastStatusCode == 303) { nreq.setRequestType(GETREQUEST); convertedToGet = true; } continue; } Loading