summaryrefslogtreecommitdiff
path: root/src/HttpResponseCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-06-29 14:29:36 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-06-29 14:29:36 +0000
commitd791807addd686660fd75d721b3cb0cf14d52f67 (patch)
treec882dc44d5456d37fb8738e53cc46618b1b87bab /src/HttpResponseCommand.cc
parent6c4dd16c82fe8dadd7a598cca998b4273436f0bd (diff)
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
Diffstat (limited to 'src/HttpResponseCommand.cc')
-rw-r--r--src/HttpResponseCommand.cc37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc
index b7522bd6..0cdffcc5 100644
--- a/src/HttpResponseCommand.cc
+++ b/src/HttpResponseCommand.cc
@@ -62,6 +62,8 @@
#include "StringFormat.h"
#include "HttpSkipResponseCommand.h"
#include "HttpHeader.h"
+#include "Decoder.h"
+#include "LogFactory.h"
namespace aria2 {
@@ -194,10 +196,32 @@ static SharedHandle<TransferEncoding> getTransferEncoding
return enc;
}
+static SharedHandle<Decoder> getContentEncodingDecoder
+(const SharedHandle<HttpResponse>& httpResponse)
+{
+ SharedHandle<Decoder> decoder;
+ if(httpResponse->isContentEncodingSpecified()) {
+ decoder = httpResponse->getContentEncodingDecoder();
+ if(decoder.isNull()) {
+ LogFactory::getInstance()->info
+ ("Content-Encoding %s is specified, but the current implementation"
+ "doesn't support it. The decoding process is skipped and the"
+ "downloaded content will be still encoded.",
+ httpResponse->getContentEncoding().c_str());
+ } else {
+ decoder->init();
+ }
+ }
+ return decoder;
+}
+
bool HttpResponseCommand::skipResponseBody
(const SharedHandle<HttpResponse>& httpResponse)
{
SharedHandle<TransferEncoding> enc(getTransferEncoding(httpResponse));
+ // We don't use Content-Encoding here because this response body is just
+ // thrown away.
+
HttpSkipResponseCommand* command = new HttpSkipResponseCommand
(cuid, req, _requestGroup, httpConnection, httpResponse, e, socket);
command->setTransferDecoder(enc);
@@ -216,7 +240,10 @@ bool HttpResponseCommand::skipResponseBody
HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand(const HttpResponseHandle& httpResponse)
{
- TransferEncodingHandle enc(getTransferEncoding(httpResponse));
+ TransferEncodingHandle enc = getTransferEncoding(httpResponse);
+ SharedHandle<Decoder> contentEncodingDecoder =
+ getContentEncodingDecoder(httpResponse);
+
HttpDownloadCommand* command =
new HttpDownloadCommand(cuid, req, _requestGroup, httpConnection, e, socket);
command->setMaxDownloadSpeedLimit(e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT));
@@ -224,6 +251,14 @@ HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand(const HttpRe
command->setLowestDownloadSpeedLimit(e->option->getAsInt(PREF_LOWEST_SPEED_LIMIT));
command->setTransferDecoder(enc);
+ if(!contentEncodingDecoder.isNull()) {
+ command->setContentEncodingDecoder(contentEncodingDecoder);
+ // Since the compressed file's length are returned in the response header
+ // and the decompressed file size is unknown at this point, disable file
+ // allocation here.
+ _requestGroup->setFileAllocationEnabled(false);
+ }
+
return command;
}