mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 19:25:53 +02:00
latest changes from main repository
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSClientSession.h
|
||||
//
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/include/Poco/Net/HTTPSClientSession.h#6 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/include/Poco/Net/HTTPSClientSession.h#7 $
|
||||
//
|
||||
// Library: NetSSL_OpenSSL
|
||||
// Package: HTTPSClient
|
||||
@@ -92,28 +92,7 @@ public:
|
||||
~HTTPSClientSession();
|
||||
/// Destroys the HTTPSClientSession and closes
|
||||
/// the underlying socket.
|
||||
|
||||
std::ostream& sendRequest(HTTPRequest& request);
|
||||
/// Sends the header for the given HTTPS request to
|
||||
/// the server.
|
||||
///
|
||||
/// The HTTPSClientSession will set the request's
|
||||
/// Host and Keep-Alive headers accordingly.
|
||||
///
|
||||
/// The returned output stream can be used to write
|
||||
/// the request body. The stream is valid until
|
||||
/// receiveResponse() is called or the session
|
||||
/// is destroyed.
|
||||
|
||||
std::istream& receiveResponse(HTTPResponse& response);
|
||||
/// Receives the header for the response to the previous
|
||||
/// HTTPS request.
|
||||
///
|
||||
/// The returned input stream can be used to read
|
||||
/// the response body. The stream is valid until
|
||||
/// sendRequest() is called or the session is
|
||||
/// destroyed.
|
||||
|
||||
|
||||
protected:
|
||||
void connect(const SocketAddress& address);
|
||||
// Connects the socket to the server.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSClientSession.cpp
|
||||
//
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/src/HTTPSClientSession.cpp#11 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/src/HTTPSClientSession.cpp#12 $
|
||||
//
|
||||
// Library: NetSSL_OpenSSL
|
||||
// Package: HTTPSClient
|
||||
@@ -82,74 +82,6 @@ HTTPSClientSession::~HTTPSClientSession()
|
||||
}
|
||||
|
||||
|
||||
std::ostream& HTTPSClientSession::sendRequest(HTTPRequest& request)
|
||||
{
|
||||
deleteResponseStream();
|
||||
|
||||
bool keepAlive = getKeepAlive();
|
||||
if (connected() && !keepAlive)
|
||||
close();
|
||||
if (!connected())
|
||||
reconnect();
|
||||
if (!keepAlive)
|
||||
request.setKeepAlive(false);
|
||||
request.setHost(getHost(), getPort());
|
||||
|
||||
{
|
||||
HTTPHeaderOutputStream hos(*this);
|
||||
setReconnect(keepAlive);
|
||||
request.write(hos);
|
||||
setReconnect(false);
|
||||
setExpectResponseBody(request.getMethod() != HTTPRequest::HTTP_HEAD);
|
||||
}
|
||||
if (request.getChunkedTransferEncoding())
|
||||
setRequestStream(new HTTPChunkedOutputStream(*this));
|
||||
else if (request.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH)
|
||||
setRequestStream(new HTTPFixedLengthOutputStream(*this, request.getContentLength()));
|
||||
else if (request.getMethod() == HTTPRequest::HTTP_GET || request.getMethod() == HTTPRequest::HTTP_HEAD)
|
||||
setRequestStream(new HTTPFixedLengthOutputStream(*this, 0));
|
||||
else
|
||||
setRequestStream(new HTTPOutputStream(*this));
|
||||
|
||||
return *getRequestStream();
|
||||
}
|
||||
|
||||
|
||||
std::istream& HTTPSClientSession::receiveResponse(HTTPResponse& response)
|
||||
{
|
||||
deleteRequestStream();
|
||||
|
||||
do
|
||||
{
|
||||
response.clear();
|
||||
HTTPHeaderInputStream his(*this);
|
||||
try
|
||||
{
|
||||
response.read(his);
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
if (networkException())
|
||||
networkException()->rethrow();
|
||||
else
|
||||
throw;
|
||||
}
|
||||
}
|
||||
while (response.getStatus() == HTTPResponse::HTTP_CONTINUE);
|
||||
|
||||
if (!getExpectResponseBody())
|
||||
setResponseStream(new HTTPFixedLengthInputStream(*this, 0));
|
||||
else if (response.getChunkedTransferEncoding())
|
||||
setResponseStream(new HTTPChunkedInputStream(*this));
|
||||
else if (response.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH)
|
||||
setResponseStream(new HTTPFixedLengthInputStream(*this, response.getContentLength()));
|
||||
else
|
||||
setResponseStream(new HTTPInputStream(*this));
|
||||
|
||||
return *getResponseStream();
|
||||
}
|
||||
|
||||
|
||||
std::string HTTPSClientSession::getHostInfo() const
|
||||
{
|
||||
std::string result("https://");
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSClientSessionTest.cpp
|
||||
//
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.cpp#7 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.cpp#8 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
@@ -35,7 +35,13 @@
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPSClientSession.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/HTTPRequestHandler.h"
|
||||
#include "Poco/Net/HTTPRequestHandlerFactory.h"
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/Net/HTTPServer.h"
|
||||
#include "Poco/Net/HTTPServerResponse.h"
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
#include "Poco/Net/HTTPServerParams.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "HTTPSTestServer.h"
|
||||
@@ -44,13 +50,45 @@
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::HTTPSClientSession;
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPResponse;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using namespace Poco::Net;
|
||||
|
||||
using Poco::StreamCopier;
|
||||
|
||||
|
||||
|
||||
class TestRequestHandler: public HTTPRequestHandler
|
||||
/// Return a HTML document with the current date and time.
|
||||
{
|
||||
public:
|
||||
TestRequestHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||
{
|
||||
response.setChunkedTransferEncoding(true);
|
||||
response.setContentType(request.getContentType());
|
||||
std::ostream& ostr = response.send();
|
||||
Poco::StreamCopier::copyStream(request.stream(), ostr);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class TestRequestHandlerFactory: public HTTPRequestHandlerFactory
|
||||
{
|
||||
public:
|
||||
TestRequestHandlerFactory()
|
||||
{
|
||||
}
|
||||
|
||||
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
|
||||
{
|
||||
return new TestRequestHandler();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
HTTPSClientSessionTest::HTTPSClientSessionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
@@ -179,6 +217,39 @@ void HTTPSClientSessionTest::testPostLargeChunked()
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testPostLargeChunkedKeepAlive()
|
||||
{
|
||||
SecureServerSocket svs(32322);
|
||||
HTTPServer srv(new TestRequestHandlerFactory(), svs, new HTTPServerParams());
|
||||
srv.start();
|
||||
try
|
||||
{
|
||||
HTTPSClientSession s("localhost", srv.port());
|
||||
s.setKeepAlive(true);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/keepAlive", HTTPMessage::HTTP_1_1);
|
||||
std::string body(16000, 'x');
|
||||
request.setChunkedTransferEncoding(true);
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getChunkedTransferEncoding());
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == body);
|
||||
}
|
||||
srv.stop();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
srv.stop();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testPostSmallClose()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
@@ -297,6 +368,7 @@ CppUnit::Test* HTTPSClientSessionTest::suite()
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeIdentity);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostSmallChunked);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeChunked);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeChunkedKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostSmallClose);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeClose);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testKeepAlive);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSClientSessionTest.h
|
||||
//
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.h#7 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.h#8 $
|
||||
//
|
||||
// Definition of the HTTPSClientSessionTest class.
|
||||
//
|
||||
@@ -53,6 +53,7 @@ public:
|
||||
void testPostLargeIdentity();
|
||||
void testPostSmallChunked();
|
||||
void testPostLargeChunked();
|
||||
void testPostLargeChunkedKeepAlive();
|
||||
void testPostSmallClose();
|
||||
void testPostLargeClose();
|
||||
void testKeepAlive();
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSTestServer.cpp
|
||||
//
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.cpp#8 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.cpp#9 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
@@ -173,7 +173,10 @@ std::string HTTPSTestServer::handleRequest() const
|
||||
{
|
||||
response.append("Transfer-Encoding: chunked\r\n");
|
||||
}
|
||||
response.append("Connection: Close\r\n");
|
||||
if (_lastRequest.substr(0,15) == "POST /keepAlive")
|
||||
response.append("Connection: keep-alive\r\n");
|
||||
else
|
||||
response.append("Connection: Close\r\n");
|
||||
response.append("\r\n");
|
||||
response.append(body);
|
||||
}
|
||||
|
Reference in New Issue
Block a user