mirror of https://github.com/aria2/aria2
2009-11-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Code cleanup * src/Request.cc * src/Request.hpull/1/head
parent
7a94ae6af2
commit
48175dcb3a
|
@ -1,3 +1,9 @@
|
||||||
|
2009-11-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Code cleanup
|
||||||
|
* src/Request.cc
|
||||||
|
* src/Request.h
|
||||||
|
|
||||||
2009-11-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-11-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Rewritten Request::parseUrl()
|
Rewritten Request::parseUrl()
|
||||||
|
|
|
@ -56,18 +56,18 @@ const std::string Request::PROTO_HTTPS("https");
|
||||||
const std::string Request::PROTO_FTP("ftp");
|
const std::string Request::PROTO_FTP("ftp");
|
||||||
|
|
||||||
Request::Request():
|
Request::Request():
|
||||||
port(0), tryCount(0),
|
_port(0), _tryCount(0),
|
||||||
_redirectCount(0),
|
_redirectCount(0),
|
||||||
_supportsPersistentConnection(true),
|
_supportsPersistentConnection(true),
|
||||||
_keepAliveHint(false),
|
_keepAliveHint(false),
|
||||||
_pipeliningHint(false),
|
_pipeliningHint(false),
|
||||||
_maxPipelinedRequest(1),
|
_maxPipelinedRequest(1),
|
||||||
method(METHOD_GET),
|
_method(METHOD_GET),
|
||||||
_hasPassword(false),
|
_hasPassword(false),
|
||||||
_ipv6LiteralAddress(false)
|
_ipv6LiteralAddress(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
static std::string removeFragment(const std::string url)
|
static std::string removeFragment(const std::string& url)
|
||||||
{
|
{
|
||||||
std::string::size_type sharpIndex = url.find("#");
|
std::string::size_type sharpIndex = url.find("#");
|
||||||
if(sharpIndex == std::string::npos) {
|
if(sharpIndex == std::string::npos) {
|
||||||
|
@ -109,23 +109,23 @@ static std::string urlencode(const std::string& src)
|
||||||
|
|
||||||
bool Request::setUrl(const std::string& url) {
|
bool Request::setUrl(const std::string& url) {
|
||||||
_supportsPersistentConnection = true;
|
_supportsPersistentConnection = true;
|
||||||
this->url = url;
|
_url = url;
|
||||||
return parseUrl(urlencode(removeFragment(url)));
|
return parseUrl(urlencode(removeFragment(_url)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Request::resetUrl() {
|
bool Request::resetUrl() {
|
||||||
previousUrl = referer;
|
_previousUrl = _referer;
|
||||||
_supportsPersistentConnection = true;
|
_supportsPersistentConnection = true;
|
||||||
return parseUrl(urlencode(removeFragment(url)));
|
return parseUrl(urlencode(removeFragment(_url)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Request::setReferer(const std::string& url)
|
void Request::setReferer(const std::string& url)
|
||||||
{
|
{
|
||||||
referer = previousUrl = urlencode(removeFragment(url));
|
_referer = _previousUrl = urlencode(removeFragment(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Request::redirectUrl(const std::string& url) {
|
bool Request::redirectUrl(const std::string& url) {
|
||||||
previousUrl = A2STR::NIL;
|
_previousUrl = A2STR::NIL;
|
||||||
_supportsPersistentConnection = true;
|
_supportsPersistentConnection = true;
|
||||||
++_redirectCount;
|
++_redirectCount;
|
||||||
if(url.find("://") == std::string::npos) {
|
if(url.find("://") == std::string::npos) {
|
||||||
|
@ -133,10 +133,10 @@ bool Request::redirectUrl(const std::string& url) {
|
||||||
// field, but some servers don't obey this rule.
|
// field, but some servers don't obey this rule.
|
||||||
if(util::startsWith(url, "/")) {
|
if(util::startsWith(url, "/")) {
|
||||||
// abosulute path
|
// abosulute path
|
||||||
return parseUrl(strconcat(protocol, "://", host, url));
|
return parseUrl(strconcat(_protocol, "://", _host, url));
|
||||||
} else {
|
} else {
|
||||||
// relative path
|
// relative path
|
||||||
return parseUrl(strconcat(protocol, "://", host, dir, "/", url));
|
return parseUrl(strconcat(_protocol, "://", _host, _dir, "/", url));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return parseUrl(url);
|
return parseUrl(url);
|
||||||
|
@ -144,11 +144,11 @@ bool Request::redirectUrl(const std::string& url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Request::parseUrl(const std::string& url) {
|
bool Request::parseUrl(const std::string& url) {
|
||||||
currentUrl = url;
|
_currentUrl = url;
|
||||||
host = A2STR::NIL;
|
_host = A2STR::NIL;
|
||||||
port = 0;
|
_port = 0;
|
||||||
dir = A2STR::NIL;
|
_dir = A2STR::NIL;
|
||||||
file = A2STR::NIL;
|
_file = A2STR::NIL;
|
||||||
_query = A2STR::NIL;
|
_query = A2STR::NIL;
|
||||||
_username = A2STR::NIL;
|
_username = A2STR::NIL;
|
||||||
_password = A2STR::NIL;
|
_password = A2STR::NIL;
|
||||||
|
@ -178,9 +178,9 @@ bool Request::parseUrl(const std::string& url) {
|
||||||
// find protocol
|
// find protocol
|
||||||
std::string::size_type protocolOffset = url.find("://");
|
std::string::size_type protocolOffset = url.find("://");
|
||||||
if(protocolOffset == std::string::npos) return false;
|
if(protocolOffset == std::string::npos) return false;
|
||||||
protocol = std::string(url.begin(), url.begin()+protocolOffset);
|
_protocol = std::string(url.begin(), url.begin()+protocolOffset);
|
||||||
uint16_t defPort;
|
uint16_t defPort;
|
||||||
if((defPort = FeatureConfig::getInstance()->getDefaultPort(protocol)) == 0) {
|
if((defPort = FeatureConfig::getInstance()->getDefaultPort(_protocol)) == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// find authority
|
// find authority
|
||||||
|
@ -250,7 +250,7 @@ bool Request::parseUrl(const std::string& url) {
|
||||||
if(portFirst == authorityLast) {
|
if(portFirst == authorityLast) {
|
||||||
// If port is not specified, then we set it to default port of
|
// If port is not specified, then we set it to default port of
|
||||||
// its protocol..
|
// its protocol..
|
||||||
port = defPort;
|
_port = defPort;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
unsigned int tempPort =
|
unsigned int tempPort =
|
||||||
|
@ -258,15 +258,15 @@ bool Request::parseUrl(const std::string& url) {
|
||||||
if(65535 < tempPort) {
|
if(65535 < tempPort) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
port = tempPort;
|
_port = tempPort;
|
||||||
} catch(RecoverableException& e) {
|
} catch(RecoverableException& e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(_ipv6LiteralAddress) {
|
if(_ipv6LiteralAddress) {
|
||||||
host = std::string(hostPortFirst+1, hostLast-1);
|
_host = std::string(hostPortFirst+1, hostLast-1);
|
||||||
} else {
|
} else {
|
||||||
host = std::string(hostPortFirst, hostLast);
|
_host = std::string(hostPortFirst, hostLast);
|
||||||
}
|
}
|
||||||
// find directory and file part
|
// find directory and file part
|
||||||
std::string::const_iterator dirLast = authorityLast;
|
std::string::const_iterator dirLast = authorityLast;
|
||||||
|
@ -277,7 +277,7 @@ bool Request::parseUrl(const std::string& url) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(dirLast != queryFirst) {
|
if(dirLast != queryFirst) {
|
||||||
file = std::string(dirLast+1, queryFirst);
|
_file = std::string(dirLast+1, queryFirst);
|
||||||
}
|
}
|
||||||
// Erase duplicated slashes.
|
// Erase duplicated slashes.
|
||||||
std::string::const_iterator dirFirst = authorityLast;
|
std::string::const_iterator dirFirst = authorityLast;
|
||||||
|
@ -294,9 +294,9 @@ bool Request::parseUrl(const std::string& url) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(dirFirst == dirLast) {
|
if(dirFirst == dirLast) {
|
||||||
dir = A2STR::SLASH_C;
|
_dir = A2STR::SLASH_C;
|
||||||
} else {
|
} else {
|
||||||
dir = std::string(dirFirst, dirLast);
|
_dir = std::string(dirFirst, dirLast);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ void Request::setMaxPipelinedRequest(unsigned int num)
|
||||||
|
|
||||||
const SharedHandle<PeerStat>& Request::initPeerStat()
|
const SharedHandle<PeerStat>& Request::initPeerStat()
|
||||||
{
|
{
|
||||||
_peerStat.reset(new PeerStat(0, host, protocol));
|
_peerStat.reset(new PeerStat(0, _host, _protocol));
|
||||||
return _peerStat;
|
return _peerStat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,24 +47,24 @@ namespace aria2 {
|
||||||
|
|
||||||
class Request {
|
class Request {
|
||||||
private:
|
private:
|
||||||
std::string url;
|
std::string _url;
|
||||||
std::string currentUrl;
|
std::string _currentUrl;
|
||||||
/**
|
/**
|
||||||
* URL previously requested to the server. This is used as Referer
|
* URL previously requested to the server. This is used as Referer
|
||||||
*/
|
*/
|
||||||
std::string previousUrl;
|
std::string _previousUrl;
|
||||||
/**
|
/**
|
||||||
* URL used as Referer in the initial request
|
* URL used as Referer in the initial request
|
||||||
*/
|
*/
|
||||||
std::string referer;
|
std::string _referer;
|
||||||
std::string protocol;
|
std::string _protocol;
|
||||||
std::string host;
|
std::string _host;
|
||||||
uint16_t port;
|
uint16_t _port;
|
||||||
std::string dir;
|
std::string _dir;
|
||||||
std::string file;
|
std::string _file;
|
||||||
/* after ? mark(includes '?' itself) */
|
/* after ? mark(includes '?' itself) */
|
||||||
std::string _query;
|
std::string _query;
|
||||||
unsigned int tryCount;
|
unsigned int _tryCount;
|
||||||
|
|
||||||
unsigned int _redirectCount;
|
unsigned int _redirectCount;
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ private:
|
||||||
// maximum number of pipelined requests
|
// maximum number of pipelined requests
|
||||||
unsigned int _maxPipelinedRequest;
|
unsigned int _maxPipelinedRequest;
|
||||||
|
|
||||||
std::string method;
|
std::string _method;
|
||||||
|
|
||||||
std::string _username;
|
std::string _username;
|
||||||
|
|
||||||
|
@ -93,18 +93,16 @@ private:
|
||||||
public:
|
public:
|
||||||
Request();
|
Request();
|
||||||
|
|
||||||
// Parses URL and sets url, host, port, dir, file fields.
|
// Sets url to _url and parses URL. Returns true if parsing goes
|
||||||
// Returns true if parsing goes successful, otherwise returns false.
|
// successful, otherwise returns false.
|
||||||
bool setUrl(const std::string& url);
|
bool setUrl(const std::string& url);
|
||||||
// Parses URL and sets host, port, dir, file fields.
|
// Parses URL. _url field are not altered by this method. Returns
|
||||||
// url field are not altered by this method.
|
// true if parsing goes successful, otherwise returns false.
|
||||||
// Returns true if parsing goes successful, otherwise returns false.
|
|
||||||
bool redirectUrl(const std::string& url);
|
bool redirectUrl(const std::string& url);
|
||||||
bool resetUrl();
|
bool resetUrl();
|
||||||
void resetTryCount() { tryCount = 0; }
|
void resetTryCount() { _tryCount = 0; }
|
||||||
void addTryCount() { ++tryCount; }
|
void addTryCount() { ++_tryCount; }
|
||||||
unsigned int getTryCount() const { return tryCount; }
|
unsigned int getTryCount() const { return _tryCount; }
|
||||||
//bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; }
|
|
||||||
|
|
||||||
void resetRedirectCount();
|
void resetRedirectCount();
|
||||||
|
|
||||||
|
@ -114,13 +112,13 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns URI passed by setUrl()
|
// Returns URI passed by setUrl()
|
||||||
const std::string& getUrl() const { return url; }
|
const std::string& getUrl() const { return _url; }
|
||||||
const std::string& getCurrentUrl() const { return currentUrl; }
|
const std::string& getCurrentUrl() const { return _currentUrl; }
|
||||||
const std::string& getPreviousUrl() const { return previousUrl; }
|
const std::string& getPreviousUrl() const { return _previousUrl; }
|
||||||
const std::string& getReferer() const { return referer; }
|
const std::string& getReferer() const { return _referer; }
|
||||||
void setReferer(const std::string& url);
|
void setReferer(const std::string& url);
|
||||||
const std::string& getProtocol() const { return protocol; }
|
const std::string& getProtocol() const { return _protocol; }
|
||||||
const std::string& getHost() const { return host; }
|
const std::string& getHost() const { return _host; }
|
||||||
// Same as getHost(), but for IPv6 literal addresses, enclose them
|
// Same as getHost(), but for IPv6 literal addresses, enclose them
|
||||||
// with square brackets and return.
|
// with square brackets and return.
|
||||||
std::string getURIHost() const
|
std::string getURIHost() const
|
||||||
|
@ -131,9 +129,9 @@ public:
|
||||||
return getHost();
|
return getHost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint16_t getPort() const { return port; }
|
uint16_t getPort() const { return _port; }
|
||||||
const std::string& getDir() const { return dir; }
|
const std::string& getDir() const { return _dir; }
|
||||||
const std::string& getFile() const { return file;}
|
const std::string& getFile() const { return _file;}
|
||||||
const std::string& getQuery() const { return _query; }
|
const std::string& getQuery() const { return _query; }
|
||||||
bool isIPv6LiteralAddress() const { return _ipv6LiteralAddress; }
|
bool isIPv6LiteralAddress() const { return _ipv6LiteralAddress; }
|
||||||
|
|
||||||
|
@ -180,7 +178,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMethod(const std::string& method) {
|
void setMethod(const std::string& method) {
|
||||||
this->method = method;
|
_method = method;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& getUsername() const
|
const std::string& getUsername() const
|
||||||
|
@ -200,7 +198,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& getMethod() const {
|
const std::string& getMethod() const {
|
||||||
return method;
|
return _method;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SharedHandle<PeerStat>& getPeerStat() const { return _peerStat; }
|
const SharedHandle<PeerStat>& getPeerStat() const { return _peerStat; }
|
||||||
|
|
Loading…
Reference in New Issue