2010-06-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Renamed member variables.
	* src/HttpResponse.cc
	* src/HttpResponse.h
pull/1/head
Tatsuhiro Tsujikawa 2010-06-12 09:57:16 +00:00
parent f9c77a25ec
commit 60995f1c5d
3 changed files with 59 additions and 53 deletions

View File

@ -1,3 +1,9 @@
2010-06-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Renamed member variables.
* src/HttpResponse.cc
* src/HttpResponse.h
2010-06-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-06-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Renamed member variables. Renamed member variables.

View File

@ -57,8 +57,8 @@
namespace aria2 { namespace aria2 {
HttpResponse::HttpResponse():cuid(0), HttpResponse::HttpResponse():_cuid(0),
logger(LogFactory::getInstance()) _logger(LogFactory::getInstance())
{} {}
HttpResponse::~HttpResponse() {} HttpResponse::~HttpResponse() {}
@ -70,21 +70,21 @@ void HttpResponse::validateResponse() const
return; return;
} }
if(status >= HttpHeader::S300) { if(status >= HttpHeader::S300) {
if(!httpHeader->defined(HttpHeader::LOCATION)) { if(!_httpHeader->defined(HttpHeader::LOCATION)) {
throw DL_ABORT_EX throw DL_ABORT_EX
(StringFormat(EX_LOCATION_HEADER_REQUIRED, (StringFormat(EX_LOCATION_HEADER_REQUIRED,
util::parseUInt(status)).str()); util::parseUInt(status)).str());
} }
} else if(!httpHeader->defined(HttpHeader::TRANSFER_ENCODING)) { } else if(!_httpHeader->defined(HttpHeader::TRANSFER_ENCODING)) {
// compare the received range against the requested range // compare the received range against the requested range
RangeHandle responseRange = httpHeader->getRange(); RangeHandle responseRange = _httpHeader->getRange();
if(!httpRequest->isRangeSatisfied(responseRange)) { if(!_httpRequest->isRangeSatisfied(responseRange)) {
throw DL_ABORT_EX2 throw DL_ABORT_EX2
(StringFormat (StringFormat
(EX_INVALID_RANGE_HEADER, (EX_INVALID_RANGE_HEADER,
util::itos(httpRequest->getStartByte(), true).c_str(), util::itos(_httpRequest->getStartByte(), true).c_str(),
util::itos(httpRequest->getEndByte(), true).c_str(), util::itos(_httpRequest->getEndByte(), true).c_str(),
util::uitos(httpRequest->getEntityLength(), true).c_str(), util::uitos(_httpRequest->getEntityLength(), true).c_str(),
util::itos(responseRange->getStartByte(), true).c_str(), util::itos(responseRange->getStartByte(), true).c_str(),
util::itos(responseRange->getEndByte(), true).c_str(), util::itos(responseRange->getEndByte(), true).c_str(),
util::uitos(responseRange->getEntityLength(), true).c_str()).str(), util::uitos(responseRange->getEntityLength(), true).c_str()).str(),
@ -97,18 +97,18 @@ std::string HttpResponse::determinFilename() const
{ {
std::string contentDisposition = std::string contentDisposition =
util::getContentDispositionFilename util::getContentDispositionFilename
(httpHeader->getFirst(HttpHeader::CONTENT_DISPOSITION)); (_httpHeader->getFirst(HttpHeader::CONTENT_DISPOSITION));
if(contentDisposition.empty()) { if(contentDisposition.empty()) {
std::string file = util::percentDecode(httpRequest->getFile()); std::string file = util::percentDecode(_httpRequest->getFile());
if(file.empty()) { if(file.empty()) {
return "index.html"; return "index.html";
} else { } else {
return file; return file;
} }
} else { } else {
if(logger->info()) { if(_logger->info()) {
logger->info(MSG_CONTENT_DISPOSITION_DETECTED, _logger->info(MSG_CONTENT_DISPOSITION_DETECTED,
util::itos(cuid).c_str(), contentDisposition.c_str()); util::itos(_cuid).c_str(), contentDisposition.c_str());
} }
return contentDisposition; return contentDisposition;
} }
@ -116,12 +116,12 @@ std::string HttpResponse::determinFilename() const
void HttpResponse::retrieveCookie() void HttpResponse::retrieveCookie()
{ {
std::vector<std::string> v = httpHeader->get(HttpHeader::SET_COOKIE); std::vector<std::string> v = _httpHeader->get(HttpHeader::SET_COOKIE);
for(std::vector<std::string>::const_iterator itr = v.begin(), eoi = v.end(); for(std::vector<std::string>::const_iterator itr = v.begin(), eoi = v.end();
itr != eoi; ++itr) { itr != eoi; ++itr) {
httpRequest->getCookieStorage()->parseAndStore(*itr, _httpRequest->getCookieStorage()->parseAndStore(*itr,
httpRequest->getHost(), _httpRequest->getHost(),
httpRequest->getDir()); _httpRequest->getDir());
} }
} }
@ -129,39 +129,39 @@ bool HttpResponse::isRedirect() const
{ {
const std::string& status = getResponseStatus(); const std::string& status = getResponseStatus();
return HttpHeader::S300 <= status && status < HttpHeader::S400 && return HttpHeader::S300 <= status && status < HttpHeader::S400 &&
httpHeader->defined(HttpHeader::LOCATION); _httpHeader->defined(HttpHeader::LOCATION);
} }
void HttpResponse::processRedirect() void HttpResponse::processRedirect()
{ {
if(httpRequest->getRequest()->redirectUri(getRedirectURI())) { if(_httpRequest->getRequest()->redirectUri(getRedirectURI())) {
if(logger->info()) { if(_logger->info()) {
logger->info(MSG_REDIRECT, util::itos(cuid).c_str(), _logger->info(MSG_REDIRECT, util::itos(_cuid).c_str(),
httpRequest->getRequest()->getCurrentUri().c_str()); _httpRequest->getRequest()->getCurrentUri().c_str());
} }
} else { } else {
throw DL_RETRY_EX throw DL_RETRY_EX
(StringFormat("CUID#%s - Redirect to %s failed. It may not be a valid" (StringFormat("CUID#%s - Redirect to %s failed. It may not be a valid"
" URI.", util::itos(cuid).c_str(), " URI.", util::itos(_cuid).c_str(),
httpRequest->getRequest()->getCurrentUri().c_str()).str()); _httpRequest->getRequest()->getCurrentUri().c_str()).str());
} }
} }
std::string HttpResponse::getRedirectURI() const std::string HttpResponse::getRedirectURI() const
{ {
return httpHeader->getFirst(HttpHeader::LOCATION); return _httpHeader->getFirst(HttpHeader::LOCATION);
} }
bool HttpResponse::isTransferEncodingSpecified() const bool HttpResponse::isTransferEncodingSpecified() const
{ {
return httpHeader->defined(HttpHeader::TRANSFER_ENCODING); return _httpHeader->defined(HttpHeader::TRANSFER_ENCODING);
} }
std::string HttpResponse::getTransferEncoding() const std::string HttpResponse::getTransferEncoding() const
{ {
// TODO See TODO in getTransferEncodingDecoder() // TODO See TODO in getTransferEncodingDecoder()
return httpHeader->getFirst(HttpHeader::TRANSFER_ENCODING); return _httpHeader->getFirst(HttpHeader::TRANSFER_ENCODING);
} }
SharedHandle<Decoder> HttpResponse::getTransferEncodingDecoder() const SharedHandle<Decoder> HttpResponse::getTransferEncodingDecoder() const
@ -178,12 +178,12 @@ SharedHandle<Decoder> HttpResponse::getTransferEncodingDecoder() const
bool HttpResponse::isContentEncodingSpecified() const bool HttpResponse::isContentEncodingSpecified() const
{ {
return httpHeader->defined(HttpHeader::CONTENT_ENCODING); return _httpHeader->defined(HttpHeader::CONTENT_ENCODING);
} }
const std::string& HttpResponse::getContentEncoding() const const std::string& HttpResponse::getContentEncoding() const
{ {
return httpHeader->getFirst(HttpHeader::CONTENT_ENCODING); return _httpHeader->getFirst(HttpHeader::CONTENT_ENCODING);
} }
SharedHandle<Decoder> HttpResponse::getContentEncodingDecoder() const SharedHandle<Decoder> HttpResponse::getContentEncodingDecoder() const
@ -199,75 +199,75 @@ SharedHandle<Decoder> HttpResponse::getContentEncodingDecoder() const
uint64_t HttpResponse::getContentLength() const uint64_t HttpResponse::getContentLength() const
{ {
if(httpHeader.isNull()) { if(_httpHeader.isNull()) {
return 0; return 0;
} else { } else {
return httpHeader->getRange()->getContentLength(); return _httpHeader->getRange()->getContentLength();
} }
} }
uint64_t HttpResponse::getEntityLength() const uint64_t HttpResponse::getEntityLength() const
{ {
if(httpHeader.isNull()) { if(_httpHeader.isNull()) {
return 0; return 0;
} else { } else {
return httpHeader->getRange()->getEntityLength(); return _httpHeader->getRange()->getEntityLength();
} }
} }
std::string HttpResponse::getContentType() const std::string HttpResponse::getContentType() const
{ {
if(httpHeader.isNull()) { if(_httpHeader.isNull()) {
return A2STR::NIL; return A2STR::NIL;
} else { } else {
return return
util::split(httpHeader->getFirst(HttpHeader::CONTENT_TYPE), ";").first; util::split(_httpHeader->getFirst(HttpHeader::CONTENT_TYPE), ";").first;
} }
} }
void HttpResponse::setHttpHeader(const SharedHandle<HttpHeader>& httpHeader) void HttpResponse::setHttpHeader(const SharedHandle<HttpHeader>& httpHeader)
{ {
this->httpHeader = httpHeader; _httpHeader = httpHeader;
} }
void HttpResponse::setHttpRequest(const SharedHandle<HttpRequest>& httpRequest) void HttpResponse::setHttpRequest(const SharedHandle<HttpRequest>& httpRequest)
{ {
this->httpRequest = httpRequest; _httpRequest = httpRequest;
} }
// TODO return std::string // TODO return std::string
const std::string& HttpResponse::getResponseStatus() const const std::string& HttpResponse::getResponseStatus() const
{ {
return httpHeader->getResponseStatus(); return _httpHeader->getResponseStatus();
} }
bool HttpResponse::hasRetryAfter() const bool HttpResponse::hasRetryAfter() const
{ {
return httpHeader->defined(HttpHeader::RETRY_AFTER); return _httpHeader->defined(HttpHeader::RETRY_AFTER);
} }
time_t HttpResponse::getRetryAfter() const time_t HttpResponse::getRetryAfter() const
{ {
return httpHeader->getFirstAsUInt(HttpHeader::RETRY_AFTER); return _httpHeader->getFirstAsUInt(HttpHeader::RETRY_AFTER);
} }
Time HttpResponse::getLastModifiedTime() const Time HttpResponse::getLastModifiedTime() const
{ {
return Time::parseHTTPDate(httpHeader->getFirst(HttpHeader::LAST_MODIFIED)); return Time::parseHTTPDate(_httpHeader->getFirst(HttpHeader::LAST_MODIFIED));
} }
bool HttpResponse::supportsPersistentConnection() const bool HttpResponse::supportsPersistentConnection() const
{ {
std::string connection = std::string connection =
util::toLower(httpHeader->getFirst(HttpHeader::CONNECTION)); util::toLower(_httpHeader->getFirst(HttpHeader::CONNECTION));
std::string version = httpHeader->getVersion(); std::string version = _httpHeader->getVersion();
return return
connection.find(HttpHeader::CLOSE) == std::string::npos && connection.find(HttpHeader::CLOSE) == std::string::npos &&
(version == HttpHeader::HTTP_1_1 || (version == HttpHeader::HTTP_1_1 ||
connection.find("keep-alive") != std::string::npos) && connection.find("keep-alive") != std::string::npos) &&
(!httpRequest->isProxyRequestSet() || (!_httpRequest->isProxyRequestSet() ||
util::toLower(httpHeader->getFirst("Proxy-Connection")).find("keep-alive") util::toLower(_httpHeader->getFirst("Proxy-Connection")).find("keep-alive")
!= std::string::npos); != std::string::npos);
} }

View File

@ -52,10 +52,10 @@ class Decoder;
class HttpResponse { class HttpResponse {
private: private:
cuid_t cuid; cuid_t _cuid;
SharedHandle<HttpRequest> httpRequest; SharedHandle<HttpRequest> _httpRequest;
SharedHandle<HttpHeader> httpHeader; SharedHandle<HttpHeader> _httpHeader;
Logger* logger; Logger* _logger;
public: public:
HttpResponse(); HttpResponse();
@ -105,7 +105,7 @@ public:
const SharedHandle<HttpHeader>& getHttpHeader() const const SharedHandle<HttpHeader>& getHttpHeader() const
{ {
return httpHeader; return _httpHeader;
} }
const std::string& getResponseStatus() const; const std::string& getResponseStatus() const;
@ -114,12 +114,12 @@ public:
const SharedHandle<HttpRequest>& getHttpRequest() const const SharedHandle<HttpRequest>& getHttpRequest() const
{ {
return httpRequest; return _httpRequest;
} }
void setCuid(cuid_t cuid) void setCuid(cuid_t cuid)
{ {
this->cuid = cuid; _cuid = cuid;
} }
bool hasRetryAfter() const; bool hasRetryAfter() const;