latest changes from main repository

This commit is contained in:
Guenter Obiltschnig
2007-04-27 13:25:16 +00:00
parent 5caf218376
commit 4d80e24d44
28 changed files with 244 additions and 165 deletions

View File

@@ -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);

View File

@@ -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();

View File

@@ -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);
}