void HTTPSStreamFactoryTest::testRedirect() { HTTPSTestServer server; HTTPSStreamFactory factory; URI uri("https://localhost/redirect"); uri.setPort(server.port()); std::auto_ptr<std::istream> pStr(factory.open(uri)); std::ostringstream ostr; StreamCopier::copyStream(*pStr.get(), ostr); assert (ostr.str() == HTTPSTestServer::LARGE_BODY); }
void HTTPSClientSessionTest::testHead() { HTTPSTestServer srv; HTTPSClientSession s("localhost", srv.port()); HTTPRequest request(HTTPRequest::HTTP_HEAD, "/large"); s.sendRequest(request); HTTPResponse response; std::istream& rs = s.receiveResponse(response); assert (response.getContentLength() == HTTPSTestServer::LARGE_BODY.length()); assert (response.getContentType() == "text/plain"); std::ostringstream ostr; assert (StreamCopier::copyStream(rs, ostr) == 0); }
void HTTPSClientSessionTest::testGetSmall() { HTTPSTestServer srv; HTTPSClientSession s("localhost", srv.port()); HTTPRequest request(HTTPRequest::HTTP_GET, "/small"); s.sendRequest(request); HTTPResponse response; std::istream& rs = s.receiveResponse(response); assert (response.getContentLength() == HTTPSTestServer::SMALL_BODY.length()); assert (response.getContentType() == "text/plain"); std::ostringstream ostr; StreamCopier::copyStream(rs, ostr); assert (ostr.str() == HTTPSTestServer::SMALL_BODY); }
void HTTPSClientSessionTest::testUnknownContentLength() { HTTPSTestServer srv; HTTPSClientSession s("127.0.0.1", srv.port()); HTTPRequest request(HTTPRequest::HTTP_GET, "/nolength"); s.sendRequest(request); HTTPResponse response; std::istream& rs = s.receiveResponse(response); assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH); assert (response.getContentType() == "text/plain"); std::ostringstream ostr; StreamCopier::copyStream(rs, ostr); assert (ostr.str() == HTTPSTestServer::SMALL_BODY); }
void HTTPSClientSessionTest::testPostLargeClose() { HTTPSTestServer srv; HTTPSClientSession s("localhost", 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); assert (!response.getChunkedTransferEncoding()); assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH); std::ostringstream ostr; StreamCopier::copyStream(rs, ostr); assert (ostr.str() == body); }
void HTTPSClientSessionTest::testPostSmallIdentity() { HTTPSTestServer srv; HTTPSClientSession s("localhost", srv.port()); HTTPRequest request(HTTPRequest::HTTP_POST, "/echo"); std::string body("this is a random request body\r\n0\r\n"); request.setContentLength((int) body.length()); s.sendRequest(request) << body; HTTPResponse response; std::istream& rs = s.receiveResponse(response); assert (response.getContentLength() == body.length()); std::ostringstream ostr; StreamCopier::copyStream(rs, ostr); assert (ostr.str() == body); }
void HTTPSStreamFactoryTest::testRedirect() { HTTPSTestServer server; HTTPSStreamFactory factory; URI uri("https://127.0.0.1/redirect"); uri.setPort(server.port()); #ifndef POCO_ENABLE_CPP11 std::auto_ptr<std::istream> pStr(factory.open(uri)); #else std::unique_ptr<std::istream> pStr(factory.open(uri)); #endif // POCO_ENABLE_CPP11 std::ostringstream ostr; StreamCopier::copyStream(*pStr.get(), ostr); assert (ostr.str() == HTTPSTestServer::LARGE_BODY); }
void HTTPSStreamFactoryTest::testError() { HTTPSTestServer server; HTTPSStreamFactory factory; URI uri("https://localhost/notfound"); uri.setPort(server.port()); try { std::istream* pStr = factory.open(uri); fail("not found - must throw"); } catch (HTTPException& exc) { std::string m = exc.displayText(); } }
void HTTPSClientSessionTest::testServerAbort() { HTTPSTestServer srv; HTTPSClientSession s("127.0.0.1", srv.port()); HTTPRequest request(HTTPRequest::HTTP_GET, "/nolength/connection/abort"); s.sendRequest(request); HTTPResponse response; std::istream& rs = s.receiveResponse(response); assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH); assert (response.getContentType() == "text/plain"); std::ostringstream ostr; StreamCopier::copyStream(rs, ostr); assert (ostr.str() == HTTPSTestServer::SMALL_BODY); assert ( dynamic_cast<const Poco::Net::SSLConnectionUnexpectedlyClosedException*>( s.networkException()) != NULL ); }
void HTTPSClientSessionTest::testPostSmallChunked() { HTTPSTestServer srv; HTTPSClientSession s("127.0.0.1", srv.port()); HTTPRequest request(HTTPRequest::HTTP_POST, "/echo"); std::string body("this is a random request body"); 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); }
void HTTPSClientSessionTest::testPostLargeIdentity() { HTTPSTestServer srv; HTTPSClientSession s("127.0.0.1", srv.port()); HTTPRequest request(HTTPRequest::HTTP_POST, "/echo"); std::string body(8000, 'x'); body.append("\r\n0\r\n"); request.setContentLength((int) body.length()); s.sendRequest(request) << body; HTTPResponse response; std::istream& rs = s.receiveResponse(response); assert (response.getContentLength() == body.length()); std::ostringstream ostr; StreamCopier::copyStream(rs, ostr); assert (ostr.str() == body); }
void HTTPSClientSessionTest::testKeepAlive() { HTTPSTestServer srv; HTTPSClientSession s("localhost", srv.port()); s.setKeepAlive(true); HTTPRequest request(HTTPRequest::HTTP_HEAD, "/keepAlive", HTTPMessage::HTTP_1_1); s.sendRequest(request); HTTPResponse response; std::istream& rs1 = s.receiveResponse(response); assert (response.getContentLength() == HTTPSTestServer::SMALL_BODY.length()); assert (response.getContentType() == "text/plain"); assert (response.getKeepAlive()); std::ostringstream ostr1; assert (StreamCopier::copyStream(rs1, ostr1) == 0); request.setMethod(HTTPRequest::HTTP_GET); request.setURI("/small"); s.sendRequest(request); std::istream& rs2 = s.receiveResponse(response); assert (response.getContentLength() == HTTPSTestServer::SMALL_BODY.length()); assert (response.getKeepAlive()); std::ostringstream ostr2; StreamCopier::copyStream(rs2, ostr2); assert (ostr2.str() == HTTPSTestServer::SMALL_BODY); request.setMethod(HTTPRequest::HTTP_GET); request.setURI("/large"); s.sendRequest(request); std::istream& rs3 = s.receiveResponse(response); assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH); assert (response.getChunkedTransferEncoding()); assert (response.getKeepAlive()); std::ostringstream ostr3; int n = StreamCopier::copyStream(rs3, ostr3); assert (ostr3.str() == HTTPSTestServer::LARGE_BODY); request.setMethod(HTTPRequest::HTTP_HEAD); request.setURI("/large"); s.sendRequest(request); std::istream& rs4= s.receiveResponse(response); assert (response.getContentLength() == HTTPSTestServer::LARGE_BODY.length()); assert (response.getContentType() == "text/plain"); assert (!response.getKeepAlive()); std::ostringstream ostr4; assert (StreamCopier::copyStream(rs4, ostr4) == 0); }