2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

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
pull/1/head
Tatsuhiro Tsujikawa 2008-05-14 14:02:18 +00:00
parent 9a98c71972
commit 158563d16a
7 changed files with 42 additions and 8 deletions

View File

@ -1,3 +1,13 @@
2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
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 <tujikawa at rednoah dot com>
Defined "\r\n", "A", "I" as static const std::string

View File

@ -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());

View File

@ -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<std::string, std::string>::value_type vt(Util::toLower(name), value);
table.insert(vt);

View File

@ -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<HttpHeader> HttpHeaderHandle;

View File

@ -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()

View File

@ -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);
}

View File

@ -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());