4646#include " Poco/Net/Context.h"
4747#include " Poco/Net/Session.h"
4848#include " Poco/Net/SSLManager.h"
49+ #include " Poco/Net/SSLException.h"
4950#include " Poco/Util/Application.h"
5051#include " Poco/Util/AbstractConfiguration.h"
5152#include " Poco/StreamCopier.h"
@@ -434,6 +435,40 @@ void HTTPSClientSessionTest::testCachedSession()
434435}
435436
436437
438+ void HTTPSClientSessionTest::testUnknownContentLength ()
439+ {
440+ HTTPSTestServer srv;
441+ HTTPSClientSession s (" localhost" , srv.port ());
442+ HTTPRequest request (HTTPRequest::HTTP_GET , " /nolength" );
443+ s.sendRequest (request);
444+ HTTPResponse response;
445+ std::istream& rs = s.receiveResponse (response);
446+ assert (response.getContentLength () == HTTPMessage::UNKNOWN_CONTENT_LENGTH );
447+ assert (response.getContentType () == " text/plain" );
448+ std::ostringstream ostr;
449+ StreamCopier::copyStream (rs, ostr);
450+ assert (ostr.str () == HTTPSTestServer::SMALL_BODY );
451+ }
452+
453+
454+ void HTTPSClientSessionTest::testServerAbort ()
455+ {
456+ HTTPSTestServer srv;
457+ HTTPSClientSession s (" localhost" , srv.port ());
458+ HTTPRequest request (HTTPRequest::HTTP_GET , " /nolength/connection/abort" );
459+ s.sendRequest (request);
460+ HTTPResponse response;
461+ std::istream& rs = s.receiveResponse (response);
462+ assert (response.getContentLength () == HTTPMessage::UNKNOWN_CONTENT_LENGTH );
463+ assert (response.getContentType () == " text/plain" );
464+ std::ostringstream ostr;
465+ StreamCopier::copyStream (rs, ostr);
466+ assert (ostr.str () == HTTPSTestServer::SMALL_BODY );
467+ assert ( dynamic_cast <const Poco::Net::SSLConnectionUnexpectedlyClosedException*>(
468+ s.networkException ()) != NULL );
469+ }
470+
471+
437472void HTTPSClientSessionTest::setUp ()
438473{
439474}
@@ -460,6 +495,8 @@ CppUnit::Test* HTTPSClientSessionTest::suite()
460495 CppUnit_addTest (pSuite, HTTPSClientSessionTest, testInterop);
461496 CppUnit_addTest (pSuite, HTTPSClientSessionTest, testProxy);
462497 CppUnit_addTest (pSuite, HTTPSClientSessionTest, testCachedSession);
498+ CppUnit_addTest (pSuite, HTTPSClientSessionTest, testUnknownContentLength);
499+ CppUnit_addTest (pSuite, HTTPSClientSessionTest, testServerAbort);
463500
464501 return pSuite;
465502}
0 commit comments