mirror of
https://github.com/pocoproject/poco.git
synced 2026-01-12 00:04:54 +08:00
fix(Net): HTTP client request body RFC compliance #4935
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -32,8 +32,6 @@ public:
|
||||
void testPostLargeIdentity();
|
||||
void testPostSmallChunked();
|
||||
void testPostLargeChunked();
|
||||
void testPostSmallClose();
|
||||
void testPostLargeClose();
|
||||
void testKeepAlive();
|
||||
void testTrailer();
|
||||
void testProxy();
|
||||
|
||||
Reference in New Issue
Block a user