浏览代码

Use uri::UriStruct in Request.h

Tatsuhiro Tsujikawa 14 年之前
父节点
当前提交
0b515d7204
共有 2 个文件被更改,包括 22 次插入53 次删除
  1. 6 16
      src/Request.cc
  2. 16 37
      src/Request.h

+ 6 - 16
src/Request.cc

@@ -57,15 +57,13 @@ const std::string Request::PROTO_HTTPS("https");
 const std::string Request::PROTO_FTP("ftp");
 
 Request::Request():
-  port_(0), tryCount_(0),
+  method_(METHOD_GET),
+  tryCount_(0),
   redirectCount_(0),
   supportsPersistentConnection_(true),
   keepAliveHint_(false),
   pipeliningHint_(false),
   maxPipelinedRequest_(1),
-  method_(METHOD_GET),
-  hasPassword_(false),
-  ipv6LiteralAddress_(false),
   removalRequested_(false),
   connectedPort_(0),
   wakeTime_(global::wallclock())
@@ -115,10 +113,11 @@ bool Request::redirectUri(const std::string& uri) {
     // field, but some servers don't obey this rule.
     if(uri[0] == '/') {
       // abosulute path
-      redirectedUri = strconcat(protocol_, "://", host_, uri);
+      redirectedUri = strconcat(us_.protocol, "://", us_.host, uri);
     } else {
       // relative path
-      redirectedUri = strconcat(protocol_, "://", host_, dir_, "/", uri);
+      redirectedUri = strconcat(us_.protocol, "://", us_.host, us_.dir,
+                                "/", uri);
     }
   } else {
     redirectedUri = uri;
@@ -130,16 +129,7 @@ bool Request::parseUri(const std::string& srcUri) {
   currentUri_ = removeFragment(srcUri);
   uri::UriStruct us;
   if(uri::parse(us, currentUri_)) {
-    protocol_.swap(us.protocol);
-    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;
+    us_.swap(us);
     return true;
   } else {
     return false;

+ 16 - 37
src/Request.h

@@ -40,6 +40,7 @@
 
 #include "SharedHandle.h"
 #include "TimerA2.h"
+#include "uri.h"
 
 namespace aria2 {
 
@@ -47,6 +48,7 @@ class PeerStat;
 
 class Request {
 private:
+  uri::UriStruct us_;
   std::string uri_;
   std::string currentUri_;
   /**
@@ -57,17 +59,12 @@ private:
    * URI used as Referer in the initial request
    */
   std::string referer_;
-  std::string protocol_;
-  std::string host_;
-  uint16_t port_;
-  std::string dir_;
-  std::string file_;
-  /* after ? mark(includes '?' itself) */
-  std::string query_;
-  unsigned int tryCount_;
+  std::string method_;
+  std::string connectedHostname_;
+  std::string connectedAddr_;
 
+  unsigned int tryCount_;
   unsigned int redirectCount_;
-
   // whether or not the server supports persistent connection
   bool supportsPersistentConnection_;
   // enable keep-alive if possible.
@@ -76,27 +73,9 @@ private:
   bool pipeliningHint_;
   // maximum number of pipelined requests
   unsigned int maxPipelinedRequest_;
-
-  std::string method_;
-
-  std::string username_;
-
-  std::string password_;
-
-  bool hasPassword_;
-
-  bool ipv6LiteralAddress_;
-
   SharedHandle<PeerStat> peerStat_;
-
   bool removalRequested_;
-
-  std::string connectedHostname_;
-
-  std::string connectedAddr_;
-
   uint16_t connectedPort_;
-
   Timer wakeTime_;
 
   bool parseUri(const std::string& uri);
@@ -121,16 +100,16 @@ public:
   const std::string& getPreviousUri() const { return previousUri_; }
   const std::string& getReferer() const { return referer_; }
   void setReferer(const std::string& uri);
-  const std::string& getProtocol() const { return protocol_; }
-  const std::string& getHost() const { return host_; }
+  const std::string& getProtocol() const { return us_.protocol; }
+  const std::string& getHost() const { return us_.host; }
   // Same as getHost(), but for IPv6 literal addresses, enclose them
   // with square brackets and return.
   std::string getURIHost() const;
-  uint16_t getPort() const { return port_; }
-  const std::string& getDir() const { return dir_; }
-  const std::string& getFile() const { return file_;}
-  const std::string& getQuery() const { return query_; }
-  bool isIPv6LiteralAddress() const { return ipv6LiteralAddress_; }
+  uint16_t getPort() const { return us_.port; }
+  const std::string& getDir() const { return us_.dir; }
+  const std::string& getFile() const { return us_.file;}
+  const std::string& getQuery() const { return us_.query; }
+  bool isIPv6LiteralAddress() const { return us_.ipv6LiteralAddress; }
 
   void supportsPersistentConnection(bool f)
   {
@@ -178,18 +157,18 @@ public:
 
   const std::string& getUsername() const
   {
-    return username_;
+    return us_.username;
   }
 
   const std::string& getPassword() const
   {
-    return password_;
+    return us_.password;
   }
 
   // Returns true if current URI has embedded password.
   bool hasPassword() const
   {
-    return hasPassword_;
+    return us_.hasPassword;
   }
 
   const std::string& getMethod() const