diff --git a/ChangeLog b/ChangeLog index 98e4a083..02e2944c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-05-14 Tatsuhiro Tsujikawa + + Made string listeral to static const std::string. + * src/HttpConnection.cc + * src/HttpHeader.cc + * src/HttpHeader.h + * src/HttpResponse.cc + 2008-05-14 Tatsuhiro Tsujikawa Made string listeral to static const std::string. diff --git a/src/HttpConnection.cc b/src/HttpConnection.cc index 8f80bf24..ca777ae7 100644 --- a/src/HttpConnection.cc +++ b/src/HttpConnection.cc @@ -138,8 +138,8 @@ HttpResponseHandle HttpConnection::receiveResponse() // Connection: close is received or the remote server is not HTTP/1.1. // We don't care whether non-HTTP/1.1 server returns Connection: keep-alive. SharedHandle httpHeader = proc->getHttpResponseHeader(); - if(Util::toLower(httpHeader->getFirst("Connection")).find("close") != std::string::npos - || httpHeader->getVersion() != "HTTP/1.1") { + if(Util::toLower(httpHeader->getFirst(HttpHeader::CONNECTION)).find(HttpHeader::CLOSE) != std::string::npos + || httpHeader->getVersion() != HttpHeader::HTTP_1_1) { entry->getHttpRequest()->getRequest()->supportsPersistentConnection(false); } else { entry->getHttpRequest()->getRequest()->supportsPersistentConnection(true); diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index e0c19341..4158f124 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -40,6 +40,26 @@ namespace aria2 { +const std::string HttpHeader::LOCATION("Location"); + +const std::string HttpHeader::TRANSFER_ENCODING("Transfer-Encoding"); + +const std::string HttpHeader::CONTENT_DISPOSITION("Content-Disposition"); + +const std::string HttpHeader::SET_COOKIE("Set-Cookie"); + +const std::string HttpHeader::CHUNKED("chunked"); + +const std::string HttpHeader::CONTENT_TYPE("Content-Type"); + +const std::string HttpHeader::RETRY_AFTER("Retry-After"); + +const std::string HttpHeader::CONNECTION("Connection"); + +const std::string HttpHeader::CLOSE("close"); + +const std::string HttpHeader::HTTP_1_1("HTTP/1.1"); + void HttpHeader::put(const std::string& name, const std::string& value) { std::multimap::value_type vt(Util::toLower(name), value); table.insert(vt); diff --git a/src/HttpHeader.h b/src/HttpHeader.h index 87c7c82c..3a09a4f9 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -78,6 +78,26 @@ public: void setVersion(const std::string& version); void fill(std::istream& in); + + static const std::string LOCATION; + + static const std::string TRANSFER_ENCODING; + + static const std::string CONTENT_DISPOSITION; + + static const std::string SET_COOKIE; + + static const std::string CHUNKED; + + static const std::string CONTENT_TYPE; + + static const std::string RETRY_AFTER; + + static const std::string CONNECTION; + + static const std::string CLOSE; + + static const std::string HTTP_1_1; }; typedef SharedHandle HttpHeaderHandle; diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index 5e120a29..2f3db240 100644 --- a/src/HttpResponse.cc +++ b/src/HttpResponse.cc @@ -64,13 +64,13 @@ void HttpResponse::validateResponse() const return; } if(status >= "300") { - if(!httpHeader->defined("Location")) { + if(!httpHeader->defined(HttpHeader::LOCATION)) { throw DlAbortEx (StringFormat(EX_LOCATION_HEADER_REQUIRED, Util::parseUInt(status)).str()); } } else { - if(!httpHeader->defined("Transfer-Encoding")) { + if(!httpHeader->defined(HttpHeader::TRANSFER_ENCODING)) { // compare the received range against the requested range RangeHandle responseRange = httpHeader->getRange(); if(!httpRequest->isRangeSatisfied(responseRange)) { @@ -91,7 +91,8 @@ void HttpResponse::validateResponse() const std::string HttpResponse::determinFilename() const { std::string contentDisposition = - Util::getContentDispositionFilename(httpHeader->getFirst("Content-Disposition")); + Util::getContentDispositionFilename + (httpHeader->getFirst(HttpHeader::CONTENT_DISPOSITION)); if(contentDisposition.empty()) { return Util::urldecode(httpRequest->getFile()); } else { @@ -103,7 +104,7 @@ std::string HttpResponse::determinFilename() const void HttpResponse::retrieveCookie() { - std::deque v = httpHeader->get("Set-Cookie"); + std::deque v = httpHeader->get(HttpHeader::SET_COOKIE); for(std::deque::const_iterator itr = v.begin(); itr != v.end(); itr++) { std::string domain = httpRequest->getHost(); std::string path = httpRequest->getDir(); @@ -114,7 +115,7 @@ void HttpResponse::retrieveCookie() bool HttpResponse::isRedirect() const { const std::string& status = getResponseStatus(); - return "300" <= status && status < "400" && httpHeader->defined("Location"); + return "300" <= status && status < "400" && httpHeader->defined(HttpHeader::LOCATION); } void HttpResponse::processRedirect() @@ -125,23 +126,23 @@ void HttpResponse::processRedirect() std::string HttpResponse::getRedirectURI() const { - return httpHeader->getFirst("Location"); + return httpHeader->getFirst(HttpHeader::LOCATION); } bool HttpResponse::isTransferEncodingSpecified() const { - return httpHeader->defined("Transfer-Encoding"); + return httpHeader->defined(HttpHeader::TRANSFER_ENCODING); } std::string HttpResponse::getTransferEncoding() const { - return httpHeader->getFirst("Transfer-Encoding"); + return httpHeader->getFirst(HttpHeader::TRANSFER_ENCODING); } TransferEncodingHandle HttpResponse::getTransferDecoder() const { if(isTransferEncodingSpecified()) { - if(getTransferEncoding() == "chunked") { + if(getTransferEncoding() == HttpHeader::CHUNKED) { return SharedHandle(new ChunkedEncoding()); } } @@ -171,7 +172,7 @@ std::string HttpResponse::getContentType() const if(httpHeader.isNull()) { return A2STR::NIL; } else { - return httpHeader->getFirst("Content-Type"); + return httpHeader->getFirst(HttpHeader::CONTENT_TYPE); } } @@ -203,12 +204,12 @@ const std::string& HttpResponse::getResponseStatus() const bool HttpResponse::hasRetryAfter() const { - return httpHeader->defined("Retry-After"); + return httpHeader->defined(HttpHeader::RETRY_AFTER); } time_t HttpResponse::getRetryAfter() const { - return httpHeader->getFirstAsUInt("Retry-After"); + return httpHeader->getFirstAsUInt(HttpHeader::RETRY_AFTER); } } // namespace aria2