summaryrefslogtreecommitdiff
path: root/src/HttpResponseCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-11-23 15:00:44 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-11-23 15:00:44 +0000
commit62105714efdf6422d049ca34808db96a2b6eabae (patch)
treee848b9fa9ceb10f62d170ac9004adb34fd724262 /src/HttpResponseCommand.cc
parentc104ac83195be28049561b027d846d836ba6cff3 (diff)
2008-11-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use HEAD method to get file size from HTTP server for segmented downloading. The request to the BitTorrent Tracker always uses GET method because the response of the tracker is small and it doesn't need segmented download. * src/FtpNegotiationCommand.cc * src/HttpRequest.cc * src/HttpResponseCommand.cc * src/HttpSkipResponseCommand.cc * src/RequestGroup.cc * src/RequestGroup.h * src/TrackerWatcherCommand.cc * test/HttpRequestTest.cc
Diffstat (limited to 'src/HttpResponseCommand.cc')
-rw-r--r--src/HttpResponseCommand.cc33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc
index 3fe1c22a..a79d3714 100644
--- a/src/HttpResponseCommand.cc
+++ b/src/HttpResponseCommand.cc
@@ -188,12 +188,6 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpResponseHandle& httpRe
HttpRequestHandle httpRequest = httpResponse->getHttpRequest();
_requestGroup->initPieceStorage();
- // quick hack for method 'head',, is it necessary?
- if(httpRequest->getMethod() == Request::METHOD_HEAD) {
- // TODO because we don't want segment file to be saved.
- return true;
- }
-
BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), e->option));
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
return true;
@@ -210,13 +204,20 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpResponseHandle& httpRe
// we can't continue to use this socket because server sends all entity
// body instead of a segment.
// Therefore, we shutdown the socket here if pipelining is enabled.
- if(!segment.isNull() && segment->getPositionToWrite() == 0 &&
+ if(req->getMethod() == Request::METHOD_GET &&
+ !segment.isNull() && segment->getPositionToWrite() == 0 &&
!req->isPipeliningEnabled()) {
command = createHttpDownloadCommand(httpResponse);
} else {
_requestGroup->getSegmentMan()->cancelSegment(cuid);
}
prepareForNextAction(command);
+ if(req->getMethod() == Request::METHOD_HEAD) {
+ if(req->supportsPersistentConnection()) {
+ e->poolSocket(req, isProxyDefined(), socket);
+ }
+ req->setMethod(Request::METHOD_GET);
+ }
} catch(Exception& e) {
delete command;
throw;
@@ -261,9 +262,12 @@ static SharedHandle<Decoder> getContentEncodingDecoder
bool HttpResponseCommand::handleOtherEncoding(const HttpResponseHandle& httpResponse) {
HttpRequestHandle httpRequest = httpResponse->getHttpRequest();
- // quick hack for method 'head',, is it necessary?
- if(httpRequest->getMethod() == Request::METHOD_HEAD) {
- return true;
+ if(req->getMethod() == Request::METHOD_HEAD) {
+ if(req->supportsPersistentConnection()) {
+ e->poolSocket(req, isProxyDefined(), socket);
+ }
+ req->setMethod(Request::METHOD_GET);
+ return prepareForRetry(0);
}
_requestGroup->initPieceStorage();
_requestGroup->shouldCancelDownloadForSafety();
@@ -286,10 +290,11 @@ bool HttpResponseCommand::skipResponseBody
(cuid, req, _requestGroup, httpConnection, httpResponse, e, socket);
command->setTransferEncodingDecoder(decoder);
- // If the response body is zero-length, set command's status to real time
- // so that avoid read check blocking
- if(httpResponse->getEntityLength() == 0 &&
- !httpResponse->isTransferEncodingSpecified()) {
+ // If request method is HEAD or the response body is zero-length,
+ // set command's status to real time so that avoid read check blocking
+ if(req->getMethod() == Request::METHOD_HEAD ||
+ (httpResponse->getEntityLength() == 0 &&
+ !httpResponse->isTransferEncodingSpecified())) {
command->setStatusRealtime();
// If entity length == 0, then socket read/write check must be disabled.
command->disableSocketCheck();