mirror of https://github.com/aria2/aria2
Use uri::UriStruct in Request.h
parent
7d68c40a77
commit
0b515d7204
|
@ -57,15 +57,13 @@ 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),
|
method_(METHOD_GET),
|
||||||
|
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),
|
|
||||||
hasPassword_(false),
|
|
||||||
ipv6LiteralAddress_(false),
|
|
||||||
removalRequested_(false),
|
removalRequested_(false),
|
||||||
connectedPort_(0),
|
connectedPort_(0),
|
||||||
wakeTime_(global::wallclock())
|
wakeTime_(global::wallclock())
|
||||||
|
@ -115,10 +113,11 @@ bool Request::redirectUri(const std::string& uri) {
|
||||||
// field, but some servers don't obey this rule.
|
// field, but some servers don't obey this rule.
|
||||||
if(uri[0] == '/') {
|
if(uri[0] == '/') {
|
||||||
// abosulute path
|
// abosulute path
|
||||||
redirectedUri = strconcat(protocol_, "://", host_, uri);
|
redirectedUri = strconcat(us_.protocol, "://", us_.host, uri);
|
||||||
} else {
|
} else {
|
||||||
// relative path
|
// relative path
|
||||||
redirectedUri = strconcat(protocol_, "://", host_, dir_, "/", uri);
|
redirectedUri = strconcat(us_.protocol, "://", us_.host, us_.dir,
|
||||||
|
"/", uri);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
redirectedUri = uri;
|
redirectedUri = uri;
|
||||||
|
@ -130,16 +129,7 @@ bool Request::parseUri(const std::string& srcUri) {
|
||||||
currentUri_ = removeFragment(srcUri);
|
currentUri_ = removeFragment(srcUri);
|
||||||
uri::UriStruct us;
|
uri::UriStruct us;
|
||||||
if(uri::parse(us, currentUri_)) {
|
if(uri::parse(us, currentUri_)) {
|
||||||
protocol_.swap(us.protocol);
|
us_.swap(us);
|
||||||
host_.swap(us.host);
|
|
||||||
port_ = us.port;
|
|
||||||
dir_.swap(us.dir);
|
|
||||||
file_.swap(us.file);
|
|
||||||
query_.swap(us.query);
|
|
||||||
username_.swap(us.username);
|
|
||||||
password_.swap(us.password);
|
|
||||||
hasPassword_ = us.hasPassword;
|
|
||||||
ipv6LiteralAddress_ = us.ipv6LiteralAddress;
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
#include "TimerA2.h"
|
#include "TimerA2.h"
|
||||||
|
#include "uri.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ class PeerStat;
|
||||||
|
|
||||||
class Request {
|
class Request {
|
||||||
private:
|
private:
|
||||||
|
uri::UriStruct us_;
|
||||||
std::string uri_;
|
std::string uri_;
|
||||||
std::string currentUri_;
|
std::string currentUri_;
|
||||||
/**
|
/**
|
||||||
|
@ -57,17 +59,12 @@ private:
|
||||||
* URI used as Referer in the initial request
|
* URI used as Referer in the initial request
|
||||||
*/
|
*/
|
||||||
std::string referer_;
|
std::string referer_;
|
||||||
std::string protocol_;
|
std::string method_;
|
||||||
std::string host_;
|
std::string connectedHostname_;
|
||||||
uint16_t port_;
|
std::string connectedAddr_;
|
||||||
std::string dir_;
|
|
||||||
std::string file_;
|
|
||||||
/* after ? mark(includes '?' itself) */
|
|
||||||
std::string query_;
|
|
||||||
unsigned int tryCount_;
|
unsigned int tryCount_;
|
||||||
|
|
||||||
unsigned int redirectCount_;
|
unsigned int redirectCount_;
|
||||||
|
|
||||||
// whether or not the server supports persistent connection
|
// whether or not the server supports persistent connection
|
||||||
bool supportsPersistentConnection_;
|
bool supportsPersistentConnection_;
|
||||||
// enable keep-alive if possible.
|
// enable keep-alive if possible.
|
||||||
|
@ -76,27 +73,9 @@ private:
|
||||||
bool pipeliningHint_;
|
bool pipeliningHint_;
|
||||||
// maximum number of pipelined requests
|
// maximum number of pipelined requests
|
||||||
unsigned int maxPipelinedRequest_;
|
unsigned int maxPipelinedRequest_;
|
||||||
|
|
||||||
std::string method_;
|
|
||||||
|
|
||||||
std::string username_;
|
|
||||||
|
|
||||||
std::string password_;
|
|
||||||
|
|
||||||
bool hasPassword_;
|
|
||||||
|
|
||||||
bool ipv6LiteralAddress_;
|
|
||||||
|
|
||||||
SharedHandle<PeerStat> peerStat_;
|
SharedHandle<PeerStat> peerStat_;
|
||||||
|
|
||||||
bool removalRequested_;
|
bool removalRequested_;
|
||||||
|
|
||||||
std::string connectedHostname_;
|
|
||||||
|
|
||||||
std::string connectedAddr_;
|
|
||||||
|
|
||||||
uint16_t connectedPort_;
|
uint16_t connectedPort_;
|
||||||
|
|
||||||
Timer wakeTime_;
|
Timer wakeTime_;
|
||||||
|
|
||||||
bool parseUri(const std::string& uri);
|
bool parseUri(const std::string& uri);
|
||||||
|
@ -121,16 +100,16 @@ public:
|
||||||
const std::string& getPreviousUri() const { return previousUri_; }
|
const std::string& getPreviousUri() const { return previousUri_; }
|
||||||
const std::string& getReferer() const { return referer_; }
|
const std::string& getReferer() const { return referer_; }
|
||||||
void setReferer(const std::string& uri);
|
void setReferer(const std::string& uri);
|
||||||
const std::string& getProtocol() const { return protocol_; }
|
const std::string& getProtocol() const { return us_.protocol; }
|
||||||
const std::string& getHost() const { return host_; }
|
const std::string& getHost() const { return us_.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;
|
||||||
uint16_t getPort() const { return port_; }
|
uint16_t getPort() const { return us_.port; }
|
||||||
const std::string& getDir() const { return dir_; }
|
const std::string& getDir() const { return us_.dir; }
|
||||||
const std::string& getFile() const { return file_;}
|
const std::string& getFile() const { return us_.file;}
|
||||||
const std::string& getQuery() const { return query_; }
|
const std::string& getQuery() const { return us_.query; }
|
||||||
bool isIPv6LiteralAddress() const { return ipv6LiteralAddress_; }
|
bool isIPv6LiteralAddress() const { return us_.ipv6LiteralAddress; }
|
||||||
|
|
||||||
void supportsPersistentConnection(bool f)
|
void supportsPersistentConnection(bool f)
|
||||||
{
|
{
|
||||||
|
@ -178,18 +157,18 @@ public:
|
||||||
|
|
||||||
const std::string& getUsername() const
|
const std::string& getUsername() const
|
||||||
{
|
{
|
||||||
return username_;
|
return us_.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& getPassword() const
|
const std::string& getPassword() const
|
||||||
{
|
{
|
||||||
return password_;
|
return us_.password;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if current URI has embedded password.
|
// Returns true if current URI has embedded password.
|
||||||
bool hasPassword() const
|
bool hasPassword() const
|
||||||
{
|
{
|
||||||
return hasPassword_;
|
return us_.hasPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& getMethod() const
|
const std::string& getMethod() const
|
||||||
|
|
Loading…
Reference in New Issue