Tatsuhiro Tsujikawa 19 éve
szülő
commit
cd5f591c41

+ 10 - 1
ChangeLog

@@ -1,5 +1,14 @@
-2006-02-22  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+2006-02-23  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	* Release 0.2.0
+	* main.cc:
+	* HttpInitiateConnectionCommand.{h,cc}:
+	* prefs.h:
+	* HttpConnection.{h,cc}: added --http-proxy-method option.
+	We can now use GET command in http proxy.
 
+2006-02-22  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+	
 	* SplitSlowestSegmentSplitter.{h,cc}: This class provies algorithm
 	that splits slowest segment of SegmentMan::commands vector.
 	This is the default split algorithm of aria2.

+ 18 - 4
src/HttpConnection.cc

@@ -41,22 +41,26 @@ void HttpConnection::sendProxyRequest() const {
     string(" HTTP/1.1\r\n")+
     "Host: "+getHost(req->getHost(), req->getPort())+"\r\n";
   if(useProxyAuth()) {
-    request += "Proxy-Authorization: Basic "+
-      Base64::encode(option->get(PREF_HTTP_PROXY_USER)+":"+
-		     option->get(PREF_HTTP_PROXY_PORT))+"\r\n";
+    request += getProxyAuthString();
   }
   request += "\r\n";
   logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
   socket->writeData(request.c_str(), request.size());
 }
 
+string HttpConnection::getProxyAuthString() const {
+  return "Proxy-Authorization: Basic "+
+    Base64::encode(option->get(PREF_HTTP_PROXY_USER)+":"+
+		   option->get(PREF_HTTP_PROXY_PORT))+"\r\n";
+}
+
 string HttpConnection::getHost(const string& host, int port) const {
   return host+(port == 80 || port == 443 ? "" : ":"+Util::llitos(port));
 }
 
 string HttpConnection::createRequest(const Segment& segment) const {
   string request = string("GET ")+
-    (req->getProtocol() == "ftp" ?
+    (req->getProtocol() == "ftp" || useProxy() && useProxyGet() ?
      req->getCurrentUrl() :
      ((req->getDir() == "/" ? "/" : req->getDir()+"/")+req->getFile()))+
     string(" HTTP/1.1\r\n")+
@@ -70,6 +74,9 @@ string HttpConnection::createRequest(const Segment& segment) const {
     request += "Range: bytes="+
       Util::llitos(segment.sp+segment.ds)+"-"+Util::llitos(segment.ep)+"\r\n";
   }
+  if(useProxy() && useProxyAuth() && useProxyGet()) {
+    request += getProxyAuthString();
+  }
   if(option->get(PREF_HTTP_AUTH_SCHEME) == V_BASIC) {
     request += "Authorization: Basic "+
       Base64::encode(option->get(PREF_HTTP_USER)+":"+
@@ -96,6 +103,9 @@ int HttpConnection::receiveResponse(HttpHeader& headers) {
   while(socket->isReadable(0)) {
     int size = sizeof(buf)-1;
     socket->peekData(buf, size);
+    if(size == 0) {
+      throw new DlRetryEx(EX_INVALID_RESPONSE);
+    }
     buf[size] = '\0';
     int hlenTemp = header.size();
     header += buf;
@@ -145,3 +155,7 @@ bool HttpConnection::useProxy() const {
 bool HttpConnection::useProxyAuth() const {
   return option->get(PREF_HTTP_PROXY_AUTH_ENABLED) == V_TRUE;
 }
+
+bool HttpConnection::useProxyGet() const {
+  return option->get(PREF_HTTP_PROXY_METHOD) == V_GET;
+}

+ 2 - 0
src/HttpConnection.h

@@ -41,6 +41,8 @@ private:
   string createRequest(const Segment& segment) const;
   bool useProxy() const;
   bool useProxyAuth() const;
+  bool useProxyGet() const;
+  string getProxyAuthString() const;
   int cuid;
   const Socket* socket;
   const Request* req;

+ 17 - 2
src/HttpInitiateConnectionCommand.cc

@@ -23,6 +23,7 @@
 #include "HttpRequestCommand.h"
 #include "HttpProxyRequestCommand.h"
 #include "Util.h"
+#include "DlAbortEx.h"
 #include "message.h"
 #include "prefs.h"
 
@@ -40,8 +41,14 @@ bool HttpInitiateConnectionCommand::executeInternal(Segment segment) {
 		    e->option->getAsInt(PREF_HTTP_PROXY_PORT));
     socket->establishConnection(e->option->get(PREF_HTTP_PROXY_HOST),
 				e->option->getAsInt(PREF_HTTP_PROXY_PORT));
-    command = new HttpProxyRequestCommand(cuid, req, e, socket);
-
+    if(useProxyTunnel()) {
+      command = new HttpProxyRequestCommand(cuid, req, e, socket);
+    } else if(useProxyGet()) {
+      command = new HttpRequestCommand(cuid, req, e, socket);
+    } else {
+      // TODO
+      throw new DlAbortEx("ERROR");
+    }
   } else {
     e->logger->info(MSG_CONNECTING_TO_SERVER, cuid, req->getHost().c_str(),
 		    req->getPort());
@@ -55,3 +62,11 @@ bool HttpInitiateConnectionCommand::executeInternal(Segment segment) {
 bool HttpInitiateConnectionCommand::useProxy() {
   return e->option->get(PREF_HTTP_PROXY_ENABLED) == V_TRUE;
 }
+
+bool HttpInitiateConnectionCommand::useProxyGet() {
+  return e->option->get(PREF_HTTP_PROXY_METHOD) == V_GET;
+}
+
+bool HttpInitiateConnectionCommand::useProxyTunnel() {
+  return e->option->get(PREF_HTTP_PROXY_METHOD) == V_TUNNEL;
+}

+ 2 - 0
src/HttpInitiateConnectionCommand.h

@@ -27,6 +27,8 @@
 class HttpInitiateConnectionCommand : public AbstractCommand {
 private:
   bool useProxy();
+  bool useProxyGet();
+  bool useProxyTunnel();
 protected:
   /**
    * Connect to the server.

+ 15 - 1
src/main.cc

@@ -124,6 +124,9 @@ void showUsage() {
   cout << " --http-passwd=PASSWD         Set HTTP password. This affects to all URLs." << endl;
   cout << " --http-proxy-user=USER       Set HTTP proxy user. This affects to all URLs" << endl;
   cout << " --http-proxy-passwd=PASSWD   Set HTTP proxy password. This affects to all URLs." << endl;
+  cout << " --http-proxy-method=METHOD   Set the method to use in proxy request." << endl;
+  cout << "                              METHOD is either 'get' or 'tunnel'." << endl;
+  cout << "                              Default: tunnel" << endl;
   cout << " --http-auth-scheme=SCHEME    Set HTTP authentication scheme. Currently, basic" << endl;
   cout << "                              is the only supported scheme. You MUST specify" << endl;
   cout << "                              this option in order to use HTTP authentication" << endl;
@@ -137,7 +140,7 @@ void showUsage() {
   cout << "                              or 'ascii'." << endl;
   cout << "                              Default: binary" << endl;
   cout << " -p, --ftp-pasv               Use passive mode in FTP." << endl;
-  cout << " --ftp-via-http-proxy=WAY     Use HTTP proxy in FTP. WAY is either 'get' or" << endl;
+  cout << " --ftp-via-http-proxy=METHOD  Use HTTP proxy in FTP. METHOD is either 'get' or" << endl;
   cout << "                              'tunnel'." << endl;
   cout << "                              Default: tunnel" << endl;
   cout << " -v, --version                Print the version number and exit." << endl;
@@ -175,6 +178,7 @@ int main(int argc, char* argv[]) {
   op->put(PREF_TIMEOUT, "60");
   op->put(PREF_MIN_SEGMENT_SIZE, "1048576");// 1M
   op->put(PREF_MAX_TRIES, "5");
+  op->put(PREF_HTTP_PROXY_METHOD, V_TUNNEL);
   op->put(PREF_FTP_USER, "anonymous");
   op->put(PREF_FTP_PASSWD, "ARIA2USER@");
   op->put(PREF_FTP_TYPE, V_BINARY);
@@ -205,6 +209,7 @@ int main(int argc, char* argv[]) {
       { "ftp-pasv", no_argument, NULL, 'p' },
       { "ftp-via-http-proxy", required_argument, &lopt, 12 },
       { "min-segment-size", required_argument, &lopt, 13 },
+      { "http-proxy-method", required_argument, &lopt, 14 },
       { "version", no_argument, NULL, 'v' },
       { "help", no_argument, NULL, 'h' },
       { 0, 0, 0, 0 }
@@ -308,6 +313,15 @@ int main(int argc, char* argv[]) {
 	op->put(PREF_MIN_SEGMENT_SIZE, Util::llitos(size));
 	break;
       }
+      case 14:
+	if(string(optarg) == V_GET || string(optarg) == V_TUNNEL) {
+	  op->put(PREF_HTTP_PROXY_METHOD, optarg);
+	} else {
+	  cerr << "http-proxy-method must be either 'get' or 'tunnel'." << endl;
+	  showUsage();
+	  exit(1);
+	}
+	break;
       }
       break;
     }

+ 2 - 0
src/prefs.h

@@ -72,6 +72,8 @@
 #define PREF_HTTP_PROXY_PASSWD "http_proxy_passwd"
 #define PREF_HTTP_PROXY_HOST "http_proxy_host"
 #define PREF_HTTP_PROXY_PORT "http_proxy_port"
+// values: get | tunnel
+#define PREF_HTTP_PROXY_METHOD "http_proxy_method"
 // values: true | false
 #define PREF_HTTP_PROXY_ENABLED "http_proxy_enabled"
 // values: true | false