2008-06-29 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Added gzip, deflate decoding support in HTTP using libz. If 
compiled
	with this feature, aria2 sends "Accept-Encoding: deflate, gzip" 
header
	to a HTTP server. If a server returns "Content-Encoding: gzip" 
or
	"Content-Encoding: deflate" then, aria2 decodes the response 
body on the
	fly and writes decoded data to a local disk.
	* README
	* README.html
	* configure.ac
	* m4/aria2_arg.m4: Added ARIA2_ARG_WITH and ARIA2_ARG_ENABLE, 
they are
	wrapper function for AC_ARG_WITH and AC_ARG_ENABLE respectively.
	* m4/libz.m4
	* src/Decoder.h
	* src/DownloadCommand.cc
	* src/DownloadCommand.h
	* src/Exception.h
	* src/GZipDecoder.cc
	* src/GZipDecoder.h
	* src/HttpHeader.cc
	* src/HttpHeader.h
	* src/HttpRequest.cc
	* src/HttpRequest.h
	* src/HttpResponse.cc
	* src/HttpResponse.h
	* src/HttpResponseCommand.cc
	* src/Makefile.am
	* test/GZipDecoderTest.cc
	* test/HttpRequestTest.cc
	* test/HttpResponseTest.cc
	* test/Makefile.am
	* test/Makefile.in
	* test/gzip_decode_test.gz
This commit is contained in:
Tatsuhiro Tsujikawa 2008-06-29 14:29:36 +00:00
parent 6c4dd16c82
commit d791807add
34 changed files with 1107 additions and 253 deletions

View file

@ -26,6 +26,7 @@ class HttpRequestTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testUserAgent);
CPPUNIT_TEST(testAddHeader);
CPPUNIT_TEST(testAddAcceptType);
CPPUNIT_TEST(testEnableAcceptEncoding);
CPPUNIT_TEST_SUITE_END();
private:
@ -43,6 +44,7 @@ public:
void testUserAgent();
void testAddHeader();
void testAddAcceptType();
void testEnableAcceptEncoding();
};
@ -119,6 +121,7 @@ void HttpRequestTest::testCreateRequest()
SharedHandle<Segment> segment(new PiecedSegment(1024, p));
HttpRequest httpRequest;
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
httpRequest.setSegment(segment);
@ -344,6 +347,7 @@ void HttpRequestTest::testCreateRequest_ftp()
SharedHandle<Piece> p(new Piece(0, 1024*1024));
SharedHandle<Segment> segment
(new PiecedSegment(1024*1024, p));
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
httpRequest.setSegment(segment);
@ -402,6 +406,7 @@ void HttpRequestTest::testCreateRequest_with_cookie()
HttpRequest httpRequest;
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
httpRequest.setSegment(segment);
@ -466,6 +471,7 @@ void HttpRequestTest::testCreateRequest_query()
SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/wiki?id=9ad5109a-b8a5-4edf-9373-56a1c34ae138");
HttpRequest httpRequest;
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
std::string expectedText =
@ -596,6 +602,7 @@ void HttpRequestTest::testUserAgent()
SharedHandle<Segment> segment(new PiecedSegment(1024, p));
HttpRequest httpRequest;
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
httpRequest.setSegment(segment);
httpRequest.setUserAgent("aria2 (Linux)");
@ -626,6 +633,7 @@ void HttpRequestTest::testAddHeader()
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2");
HttpRequest httpRequest;
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
httpRequest.addHeader("X-ARIA2: v0.13\nX-ARIA2-DISTRIBUTE: enabled\n");
@ -652,6 +660,7 @@ void HttpRequestTest::testAddAcceptType()
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2");
HttpRequest httpRequest;
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
httpRequest.addAcceptType(&acceptTypes[0], &acceptTypes[arrayLength(acceptTypes)]);
@ -668,4 +677,34 @@ void HttpRequestTest::testAddAcceptType()
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
}
void HttpRequestTest::testEnableAcceptEncoding()
{
SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2");
HttpRequest httpRequest;
httpRequest.setRequest(request);
std::string acceptEncodings;
#ifdef HAVE_LIBZ
acceptEncodings += "deflate, gzip";
#endif // HAVE_LIBZ
std::string expectedText =
"GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n"
"Accept: */*\r\n";
if(!acceptEncodings.empty()) {
expectedText += "Accept-Encoding: "+acceptEncodings+"\r\n";
}
expectedText +=
"Host: localhost\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
}
} // namespace aria2