mirror of
https://github.com/aria2/aria2.git
synced 2025-03-06 21:10:06 +00:00

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
60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
#include "GZipDecoder.h"
|
|
#include "Exception.h"
|
|
#include "Util.h"
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
# include "MessageDigestHelper.h"
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
namespace aria2 {
|
|
|
|
class GZipDecoderTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(GZipDecoderTest);
|
|
CPPUNIT_TEST(testDecode);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
public:
|
|
void setUp() {}
|
|
|
|
void tearDown() {}
|
|
|
|
void testDecode();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(GZipDecoderTest);
|
|
|
|
void GZipDecoderTest::testDecode()
|
|
{
|
|
GZipDecoder decoder;
|
|
decoder.init();
|
|
|
|
std::string outfile("/tmp/aria2_GZipDecoderTest_testDecode");
|
|
|
|
char buf[4096];
|
|
std::ifstream in("gzip_decode_test.gz");
|
|
std::ofstream out(outfile.c_str());
|
|
while(in) {
|
|
in.read(buf, sizeof(buf));
|
|
|
|
std::string r = decoder.decode
|
|
(reinterpret_cast<const unsigned char*>(buf), in.gcount());
|
|
|
|
out.write(r.data(), r.size());
|
|
}
|
|
CPPUNIT_ASSERT(decoder.finished());
|
|
decoder.release();
|
|
|
|
out.close();
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
CPPUNIT_ASSERT_EQUAL(std::string("8b577b33c0411b2be9d4fa74c7402d54a8d21f96"),
|
|
MessageDigestHelper::digest(MessageDigestContext::SHA1,
|
|
outfile));
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
}
|
|
|
|
} // namespace aria2
|