Loading src/http.cpp +33 −12 Original line number Diff line number Diff line Loading @@ -902,22 +902,43 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq std::cerr << "[HttpClient::Post] URL path: '" << nreq.getRequestURL() << "' | POST body size: " << post.size() << std::endl; // (optionally) set content-type: // nreq.setHeaderData("Content-Type")->push_back("application/json"); // Build header string, then send header + body together so the // server sees the complete request in a single TCP segment and // does not respond before the body arrives. { std::string header; nreq.printHeader(header); nreq.send(_url,_cltsock); // Ensure connection is established (same logic as send()) if (!_cltsock || _cltsock->fd() < 0) { if (!_cltsock) { if (_url.getProtocol() == HttpUrl::HTTPS) { std::map<std::string, netplus::ssl::CertificateBundle> certs; _cltsock = std::make_unique<netplus::ssl>(certs, -1); } else { _cltsock = std::make_unique<netplus::tcp>(-1); } } _cltsock->connect(_url.getHost(), _url.getPort(), true); } // Concatenate header + body into a single buffer std::vector<char> combined; combined.reserve(header.size() + post.size()); combined.insert(combined.end(), header.begin(), header.end()); combined.insert(combined.end(), post.begin(), post.end()); // Send POST body data try { size_t sended = 0; while (sended != post.size()) { netplus::buffer outbuf(post.data() + sended, post.size() - sended); while (sended != combined.size()) { netplus::buffer outbuf(combined.data() + sended, combined.size() - sended); sended += _cltsock->sendData(outbuf, 0); } } catch (netplus::NetException &e) { throw HTTPException()[HTTPException::Error] << e.what(); } } // --------------------------------------------------------- // helper: recv one chunk with Note-retry Loading Loading
src/http.cpp +33 −12 Original line number Diff line number Diff line Loading @@ -902,22 +902,43 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq std::cerr << "[HttpClient::Post] URL path: '" << nreq.getRequestURL() << "' | POST body size: " << post.size() << std::endl; // (optionally) set content-type: // nreq.setHeaderData("Content-Type")->push_back("application/json"); // Build header string, then send header + body together so the // server sees the complete request in a single TCP segment and // does not respond before the body arrives. { std::string header; nreq.printHeader(header); nreq.send(_url,_cltsock); // Ensure connection is established (same logic as send()) if (!_cltsock || _cltsock->fd() < 0) { if (!_cltsock) { if (_url.getProtocol() == HttpUrl::HTTPS) { std::map<std::string, netplus::ssl::CertificateBundle> certs; _cltsock = std::make_unique<netplus::ssl>(certs, -1); } else { _cltsock = std::make_unique<netplus::tcp>(-1); } } _cltsock->connect(_url.getHost(), _url.getPort(), true); } // Concatenate header + body into a single buffer std::vector<char> combined; combined.reserve(header.size() + post.size()); combined.insert(combined.end(), header.begin(), header.end()); combined.insert(combined.end(), post.begin(), post.end()); // Send POST body data try { size_t sended = 0; while (sended != post.size()) { netplus::buffer outbuf(post.data() + sended, post.size() - sended); while (sended != combined.size()) { netplus::buffer outbuf(combined.data() + sended, combined.size() - sended); sended += _cltsock->sendData(outbuf, 0); } } catch (netplus::NetException &e) { throw HTTPException()[HTTPException::Error] << e.what(); } } // --------------------------------------------------------- // helper: recv one chunk with Note-retry Loading