From 158563d16a78bb0138c8cd5703dd58e367d59640 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 14 May 2008 14:02:18 +0000 Subject: [PATCH] 2008-05-14 Tatsuhiro Tsujikawa Defined HTTP status as static const std::string * src/AbstractProxyResponseCommand.cc * src/HttpHeader.cc * src/HttpHeader.h * src/HttpResponse.cc * src/HttpResponseCommand.cc * src/HttpSkipResponseCommand.cc --- ChangeLog | 10 ++++++++++ src/AbstractProxyResponseCommand.cc | 3 ++- src/HttpHeader.cc | 10 ++++++++++ src/HttpHeader.h | 10 ++++++++++ src/HttpResponse.cc | 7 ++++--- src/HttpResponseCommand.cc | 3 ++- src/HttpSkipResponseCommand.cc | 7 ++++--- 7 files changed, 42 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index c50c2d2a..a16c3a98 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-05-14 Tatsuhiro Tsujikawa + + Defined HTTP status as static const std::string + * src/AbstractProxyResponseCommand.cc + * src/HttpHeader.cc + * src/HttpHeader.h + * src/HttpResponse.cc + * src/HttpResponseCommand.cc + * src/HttpSkipResponseCommand.cc + 2008-05-14 Tatsuhiro Tsujikawa Defined "\r\n", "A", "I" as static const std::string diff --git a/src/AbstractProxyResponseCommand.cc b/src/AbstractProxyResponseCommand.cc index dcab70ed..08e039cf 100644 --- a/src/AbstractProxyResponseCommand.cc +++ b/src/AbstractProxyResponseCommand.cc @@ -44,6 +44,7 @@ #include "Socket.h" #include "DlRetryEx.h" #include "message.h" +#include "HttpHeader.h" namespace aria2 { @@ -65,7 +66,7 @@ bool AbstractProxyResponseCommand::executeInternal() { e->commands.push_back(this); return false; } - if(httpResponse->getResponseStatus() != "200") { + if(httpResponse->getResponseStatus() != HttpHeader::S200) { throw DlRetryEx(EX_PROXY_CONNECTION_FAILED); } e->commands.push_back(getNextCommand()); diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 39fa0a8c..6d4c765d 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -64,6 +64,16 @@ const std::string HttpHeader::CONTENT_RANGE("Content-Range"); const std::string HttpHeader::HTTP_1_1("HTTP/1.1"); +const std::string HttpHeader::S200("200"); + +const std::string HttpHeader::S300("300"); + +const std::string HttpHeader::S400("400"); + +const std::string HttpHeader::S401("401"); + +const std::string HttpHeader::S404("404"); + 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 49c1013f..2b96feda 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -102,6 +102,16 @@ public: static const std::string CONTENT_RANGE; static const std::string HTTP_1_1; + + static const std::string S200; + + static const std::string S300; + + static const std::string S400; + + static const std::string S401; + + static const std::string S404; }; typedef SharedHandle HttpHeaderHandle; diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index 2f3db240..d51a806c 100644 --- a/src/HttpResponse.cc +++ b/src/HttpResponse.cc @@ -60,10 +60,10 @@ HttpResponse::~HttpResponse() {} void HttpResponse::validateResponse() const { const std::string& status = getResponseStatus(); - if(status >= "400") { + if(status >= HttpHeader::S400) { return; } - if(status >= "300") { + if(status >= HttpHeader::S300) { if(!httpHeader->defined(HttpHeader::LOCATION)) { throw DlAbortEx (StringFormat(EX_LOCATION_HEADER_REQUIRED, @@ -115,7 +115,8 @@ void HttpResponse::retrieveCookie() bool HttpResponse::isRedirect() const { const std::string& status = getResponseStatus(); - return "300" <= status && status < "400" && httpHeader->defined(HttpHeader::LOCATION); + return HttpHeader::S300 <= status && status < HttpHeader::S400 && + httpHeader->defined(HttpHeader::LOCATION); } void HttpResponse::processRedirect() diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index f2e6db7f..b7522bd6 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -61,6 +61,7 @@ #include "prefs.h" #include "StringFormat.h" #include "HttpSkipResponseCommand.h" +#include "HttpHeader.h" namespace aria2 { @@ -88,7 +89,7 @@ bool HttpResponseCommand::executeInternal() httpResponse->validateResponse(); httpResponse->retrieveCookie(); - if(httpResponse->getResponseStatus() >= "300") { + if(httpResponse->getResponseStatus() >= HttpHeader::S300) { return skipResponseBody(httpResponse); } diff --git a/src/HttpSkipResponseCommand.cc b/src/HttpSkipResponseCommand.cc index f58cf58d..8c263944 100644 --- a/src/HttpSkipResponseCommand.cc +++ b/src/HttpSkipResponseCommand.cc @@ -47,6 +47,7 @@ #include "Util.h" #include "StringFormat.h" #include "DlAbortEx.h" +#include "HttpHeader.h" namespace aria2 { @@ -130,10 +131,10 @@ bool HttpSkipResponseCommand::processResponse() return prepareForRetry(0); } else if(_httpResponse->hasRetryAfter()) { return prepareForRetry(_httpResponse->getRetryAfter()); - } else if(_httpResponse->getResponseStatus() >= "400") { - if(_httpResponse->getResponseStatus() == "401") { + } else if(_httpResponse->getResponseStatus() >= HttpHeader::S400) { + if(_httpResponse->getResponseStatus() == HttpHeader::S401) { throw DlAbortEx(EX_AUTH_FAILED); - }else if(_httpResponse->getResponseStatus() == "404") { + }else if(_httpResponse->getResponseStatus() == HttpHeader::S404) { throw DlAbortEx(MSG_RESOURCE_NOT_FOUND); } else { throw DlAbortEx(StringFormat(EX_BAD_STATUS, Util::parseUInt(_httpResponse->getResponseStatus())).str());