From 90c6d5072b70e51ad754c31436abf9479a288769 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 23 Oct 2008 13:51:34 +0000 Subject: [PATCH] 2008-10-23 Tatsuhiro Tsujikawa Pool connection when redirection occurs with Content-Length = 0. * src/HttpSkipResponseCommand.cc * src/HttpSkipResponseCommand.h --- ChangeLog | 6 ++++++ src/HttpSkipResponseCommand.cc | 24 ++++++++++++++++++------ src/HttpSkipResponseCommand.h | 2 ++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index deead32c..ffbe81c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-10-23 Tatsuhiro Tsujikawa + + Pool connection when redirection occurs with Content-Length = 0. + * src/HttpSkipResponseCommand.cc + * src/HttpSkipResponseCommand.h + 2008-10-22 Tatsuhiro Tsujikawa Fixed the bug that causes time out when redirection occurs with diff --git a/src/HttpSkipResponseCommand.cc b/src/HttpSkipResponseCommand.cc index 313eed7d..e7ec9742 100644 --- a/src/HttpSkipResponseCommand.cc +++ b/src/HttpSkipResponseCommand.cc @@ -80,6 +80,13 @@ void HttpSkipResponseCommand::setTransferEncodingDecoder bool HttpSkipResponseCommand::executeInternal() { if(_totalLength == 0 && _transferEncodingDecoder.isNull()) { + // If content-length header is present and it's value is 0, then + // pool socket for reuse. + // If content-length header is not present, then EOF is expected in the end. + // In this case, the content is thrown away and socket cannot be pooled. + if(_httpResponse->getHttpHeader()->defined(HttpHeader::CONTENT_LENGTH)) { + poolConnection(); + } return processResponse(); } const size_t BUFSIZE = 16*1024; @@ -118,12 +125,7 @@ bool HttpSkipResponseCommand::executeInternal() finished = _transferEncodingDecoder->finished(); } if(finished) { - if(!e->option->getAsBool(PREF_HTTP_PROXY_ENABLED) && - req->supportsPersistentConnection()) { - std::pair peerInfo; - socket->getPeerInfo(peerInfo); - e->poolSocket(peerInfo.first, peerInfo.second, socket); - } + poolConnection(); return processResponse(); } else { setWriteCheckSocketIf(socket, socket->wantWrite()); @@ -132,6 +134,16 @@ bool HttpSkipResponseCommand::executeInternal() } } +void HttpSkipResponseCommand::poolConnection() const +{ + if(!e->option->getAsBool(PREF_HTTP_PROXY_ENABLED) && + req->supportsPersistentConnection()) { + std::pair peerInfo; + socket->getPeerInfo(peerInfo); + e->poolSocket(peerInfo.first, peerInfo.second, socket); + } +} + bool HttpSkipResponseCommand::processResponse() { if(_httpResponse->isRedirect()) { diff --git a/src/HttpSkipResponseCommand.h b/src/HttpSkipResponseCommand.h index 9cae544e..7ec1a511 100644 --- a/src/HttpSkipResponseCommand.h +++ b/src/HttpSkipResponseCommand.h @@ -56,6 +56,8 @@ private: uint64_t _receivedBytes; bool processResponse(); + + void poolConnection() const; protected: virtual bool executeInternal(); public: