fix(Net): HTTP client request body RFC compliance #4935

This commit is contained in:
Günter Obiltschnig
2025-04-15 19:38:13 +02:00
parent 44c8c295ba
commit 541b2224a2
3 changed files with 1 additions and 44 deletions

View File

@@ -322,18 +322,13 @@ std::ostream& HTTPClientSession::sendRequestImpl(const HTTPRequest& request)
#endif
request.write(*_pRequestStream);
}
else if ((method != HTTPRequest::HTTP_PUT && method != HTTPRequest::HTTP_POST && method != HTTPRequest::HTTP_PATCH) || request.has(HTTPRequest::UPGRADE))
else
{
Poco::CountingOutputStream cs;
request.write(cs);
_pRequestStream = new HTTPFixedLengthOutputStream(*this, cs.chars());
request.write(*_pRequestStream);
}
else
{
_pRequestStream = new HTTPOutputStream(*this);
request.write(*_pRequestStream);
}
_lastRequest.update();
return *_pRequestStream;
}

View File

@@ -188,40 +188,6 @@ void HTTPClientSessionTest::testPostLargeChunked()
}
void HTTPClientSessionTest::testPostSmallClose()
{
HTTPTestServer srv;
HTTPClientSession s("127.0.0.1", srv.port());
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
std::string body("this is a random request body");
s.sendRequest(request) << body;
HTTPResponse response;
std::istream& rs = s.receiveResponse(response);
assertTrue (!response.getChunkedTransferEncoding());
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
std::ostringstream ostr;
StreamCopier::copyStream(rs, ostr);
assertTrue (ostr.str() == body);
}
void HTTPClientSessionTest::testPostLargeClose()
{
HTTPTestServer srv;
HTTPClientSession s("127.0.0.1", srv.port());
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
std::string body(8000, 'x');
s.sendRequest(request) << body;
HTTPResponse response;
std::istream& rs = s.receiveResponse(response);
assertTrue (!response.getChunkedTransferEncoding());
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
std::ostringstream ostr;
StreamCopier::copyStream(rs, ostr);
assertTrue (ostr.str() == body);
}
void HTTPClientSessionTest::testKeepAlive()
{
HTTPTestServer srv;
@@ -410,8 +376,6 @@ CppUnit::Test* HTTPClientSessionTest::suite()
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostLargeIdentity);
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostSmallChunked);
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostLargeChunked);
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostSmallClose);
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostLargeClose);
CppUnit_addTest(pSuite, HTTPClientSessionTest, testKeepAlive);
CppUnit_addTest(pSuite, HTTPClientSessionTest, testTrailer);
CppUnit_addTest(pSuite, HTTPClientSessionTest, testProxy);

View File

@@ -32,8 +32,6 @@ public:
void testPostLargeIdentity();
void testPostSmallChunked();
void testPostLargeChunked();
void testPostSmallClose();
void testPostLargeClose();
void testKeepAlive();
void testTrailer();
void testProxy();