~ubuntu-branches/ubuntu/quantal/aria2/quantal

« back to all changes in this revision

Viewing changes to src/HttpResponseCommand.cc

  • Committer: Bazaar Package Importer
  • Author(s): Kartik Mistry
  • Date: 2011-04-02 12:38:55 UTC
  • mfrom: (2.5.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110402123855-znkslovhf5qvkjut
Tags: 1.11.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
#include "SinkStreamFilter.h"
72
72
#include "ChunkedDecodingStreamFilter.h"
73
73
#include "uri.h"
74
 
#ifdef HAVE_LIBZ
 
74
#include "SocketRecvBuffer.h"
 
75
#ifdef HAVE_ZLIB
75
76
# include "GZipDecodingStreamFilter.h"
76
 
#endif // HAVE_LIBZ
 
77
#endif // HAVE_ZLIB
77
78
 
78
79
namespace aria2 {
79
80
 
134
135
 const HttpConnectionHandle& httpConnection,
135
136
 DownloadEngine* e,
136
137
 const SocketHandle& s)
137
 
  : AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
 
138
  : AbstractCommand(cuid, req, fileEntry, requestGroup, e, s,
 
139
                    httpConnection->getSocketRecvBuffer()),
138
140
    httpConnection_(httpConnection)
139
 
{}
 
141
{
 
142
  checkSocketRecvBuffer();
 
143
}
140
144
 
141
145
HttpResponseCommand::~HttpResponseCommand() {}
142
146
 
165
169
  if(getRequest()->isPipeliningEnabled()) {
166
170
    getRequest()->setMaxPipelinedRequest
167
171
      (getOption()->getAsInt(PREF_MAX_HTTP_PIPELINING));
 
172
  } else {
 
173
    getRequest()->setMaxPipelinedRequest(1);
168
174
  }
169
175
 
170
176
  int statusCode = httpResponse->getStatusCode();
171
 
  if(!httpResponse->getHttpRequest()->getIfModifiedSinceHeader().empty()) {
172
 
    if(statusCode == 304) {
173
 
      uint64_t totalLength = httpResponse->getEntityLength();
174
 
      getFileEntry()->setLength(totalLength);
175
 
      getRequestGroup()->initPieceStorage();
176
 
      getPieceStorage()->markAllPiecesDone();
177
 
      // Just set checksum verification done.
178
 
      getDownloadContext()->setChecksumVerified(true);
179
 
      A2_LOG_NOTICE(fmt(MSG_DOWNLOAD_ALREADY_COMPLETED,
180
 
                        util::itos(getRequestGroup()->getGID()).c_str(),
181
 
                        getRequestGroup()->getFirstFilePath().c_str()));
182
 
      poolConnection();
183
 
      getFileEntry()->poolRequest(getRequest());
184
 
      return true;
185
 
    } else if(statusCode == 200 || statusCode == 206) {
186
 
      // Remote file is newer than local file. We allow overwrite.
187
 
      getOption()->put(PREF_ALLOW_OVERWRITE, A2_V_TRUE);
188
 
    }
 
177
 
 
178
  if(statusCode == 304) {
 
179
    uint64_t totalLength = httpResponse->getEntityLength();
 
180
    getFileEntry()->setLength(totalLength);
 
181
    getRequestGroup()->initPieceStorage();
 
182
    getPieceStorage()->markAllPiecesDone();
 
183
    // Just set checksum verification done.
 
184
    getDownloadContext()->setChecksumVerified(true);
 
185
    A2_LOG_NOTICE(fmt(MSG_DOWNLOAD_ALREADY_COMPLETED,
 
186
                      util::itos(getRequestGroup()->getGID()).c_str(),
 
187
                      getRequestGroup()->getFirstFilePath().c_str()));
 
188
    poolConnection();
 
189
    getFileEntry()->poolRequest(getRequest());
 
190
    return true;
189
191
  }
190
 
  if(statusCode != 304 && statusCode >= 300) {
 
192
  if(statusCode >= 300) {
191
193
    if(statusCode == 404) {
192
194
      getRequestGroup()->increaseAndValidateFileNotFoundCount();
193
195
    }
445
447
bool decideFileAllocation
446
448
(const SharedHandle<StreamFilter>& filter)
447
449
{
448
 
#ifdef HAVE_LIBZ
 
450
#ifdef HAVE_ZLIB
449
451
  for(SharedHandle<StreamFilter> f = filter; f; f = f->getDelegate()){
450
452
    // Since the compressed file's length are returned in the response header
451
453
    // and the decompressed file size is unknown at this point, disable file
454
456
      return false;
455
457
    }
456
458
  }
457
 
#endif // HAVE_LIBZ
 
459
#endif // HAVE_ZLIB
458
460
  return true;
459
461
}
460
462
} // namespace