diff options
author | Tobias Markmann <tm@ayena.de> | 2015-03-17 12:55:12 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2015-03-19 18:44:21 (GMT) |
commit | cd193389d65c4abd51c557f942348f36356f4788 (patch) | |
tree | 77f6fea1542cc1f9dba6c299f74dc3bfbe0b1dde /Swiften/Network/UnitTest | |
parent | fedd8d88befb0fa19a58a78a163c200889b5272c (diff) | |
download | swift-cd193389d65c4abd51c557f942348f36356f4788.zip swift-cd193389d65c4abd51c557f942348f36356f4788.tar.bz2 |
Fix for HTTPConnectProxiedConnection to support responses in pieces
This fix lets HTTPConnectProxiedConnection buffer response data in
pieces until the end of the HTTP header is reached. Only then it will
try to parse the HTTP header.
This is *not* the HTTP chunked transfer encoding.
Test-Information:
Adjusted one test to respond in pieces and added a new test case that
verifies that response data is buffered.
Change-Id: Icfb987bdf2fc5771401a8a9c6979fa9ad1eebdca
Diffstat (limited to 'Swiften/Network/UnitTest')
-rw-r--r-- | Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp b/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp index fb6914e..d3db79d 100644 --- a/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp +++ b/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp @@ -49,6 +49,7 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture { CPPUNIT_TEST(testConnect_CreatesConnectionToProxy); CPPUNIT_TEST(testConnect_SendsConnectRequest); CPPUNIT_TEST(testConnect_ReceiveConnectResponse); + CPPUNIT_TEST(testConnect_ReceiveConnectChunkedResponse); CPPUNIT_TEST(testConnect_ReceiveMalformedConnectResponse); CPPUNIT_TEST(testConnect_ReceiveErrorConnectResponse); CPPUNIT_TEST(testConnect_ReceiveDataAfterConnect); @@ -118,6 +119,21 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(dataRead.empty()); } + void testConnect_ReceiveConnectChunkedResponse() { + HTTPConnectProxiedConnection::ref testling(createTestling()); + connect(testling, HostAddressPort(HostAddress("2.2.2.2"), 2345)); + + connectionFactory->connections[0]->onDataRead(createSafeByteArrayRef("HTTP/1.0 ")); + eventLoop->processEvents(); + connectionFactory->connections[0]->onDataRead(createSafeByteArrayRef("200 Connection established\r\n\r\n")); + eventLoop->processEvents(); + + CPPUNIT_ASSERT(connectFinished); + CPPUNIT_ASSERT(!connectFinishedWithError); + CPPUNIT_ASSERT(dataRead.empty()); + } + + void testConnect_ReceiveMalformedConnectResponse() { HTTPConnectProxiedConnection::ref testling(createTestling()); connect(testling, HostAddressPort(HostAddress("2.2.2.2"), 2345)); @@ -203,12 +219,16 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture { connectionFactory->connections[0]->dataWritten.clear(); + // test chunked response + connectionFactory->connections[0]->onDataRead(createSafeByteArrayRef( + "HTTP/1.0 401 Unauthorized\r\n")); + eventLoop->processEvents(); connectionFactory->connections[0]->onDataRead(createSafeByteArrayRef( - "HTTP/1.0 401 Unauthorized\r\n" "WWW-Authenticate: Negotiate\r\n" "\r\n")); eventLoop->processEvents(); + // verify that the traffic filter got called and answered with its response CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), httpTrafficFilter->filterResponses.size()); CPPUNIT_ASSERT_EQUAL(std::string("WWW-Authenticate"), httpTrafficFilter->filterResponses[0][0].first); |