Răsfoiți Sursa

2008-12-29 Tatsuhiro Tsujikawa <[email protected]>

	Added --use-head option to toggle whether HEAD method should be
	used in the first HTTP request. By default aria2 uses HEAD
	method as the first request. When the server doesn't recognize
	HEAD, then give aria2 --use-head=false to force aria2 to use GET
	method instead.
	* src/OptionHandlerFactory.cc
	* src/RequestGroupMan.cc
	* src/option_processing.cc
	* src/prefs.cc
	* src/prefs.h
	* src/usage_text.h
Tatsuhiro Tsujikawa 17 ani în urmă
părinte
comite
5db28b5a03
7 a modificat fișierele cu 48 adăugiri și 2 ștergeri
  1. 14 0
      ChangeLog
  2. 8 0
      src/OptionHandlerFactory.cc
  3. 15 2
      src/RequestGroupMan.cc
  4. 4 0
      src/option_processing.cc
  5. 2 0
      src/prefs.cc
  6. 2 0
      src/prefs.h
  7. 3 0
      src/usage_text.h

+ 14 - 0
ChangeLog

@@ -1,3 +1,17 @@
+2008-12-29  Tatsuhiro Tsujikawa  <[email protected]>
+
+	Added --use-head option to toggle whether HEAD method should be
+	used in the first HTTP request. By default aria2 uses HEAD method
+	as the first request. When the server doesn't recognize HEAD, then
+	give aria2 --use-head=false to force aria2 to use GET method
+	instead.
+	* src/OptionHandlerFactory.cc
+	* src/RequestGroupMan.cc
+	* src/option_processing.cc
+	* src/prefs.cc
+	* src/prefs.h
+	* src/usage_text.h
+
 2008-12-29  Tatsuhiro Tsujikawa  <[email protected]>
 
 	Fixed the bug that BitTorrent download doesn't finish when REJECT

+ 8 - 0
src/OptionHandlerFactory.cc

@@ -539,6 +539,14 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
     op->addTag(TAG_HTTP);
     handlers.push_back(op);
   }
+  {
+    SharedHandle<OptionHandler> op(new DefaultOptionHandler
+				   (PREF_USE_HEAD,
+				    TEXT_USE_HEAD,
+				    V_TRUE));
+    op->addTag(TAG_HTTP);
+    handlers.push_back(op);
+  }
   {
     SharedHandle<OptionHandler> op(new DefaultOptionHandler
 				   (PREF_USER_AGENT,

+ 15 - 2
src/RequestGroupMan.cc

@@ -268,6 +268,17 @@ void RequestGroupMan::configureRequestGroup
   }
 }
 
+static void createInitialCommand(const SharedHandle<RequestGroup>& requestGroup,
+				 std::deque<Command*>& commands,
+				 DownloadEngine* e,
+				 bool useHead)
+{
+  requestGroup->createInitialCommand(commands, e,
+				     useHead ?
+				     Request::METHOD_HEAD :
+				     Request::METHOD_GET);
+}
+
 void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
 {
   RequestGroups temp;
@@ -284,7 +295,8 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
       }
       configureRequestGroup(groupToAdd);
       Commands commands;
-      groupToAdd->createInitialCommand(commands, e);
+      createInitialCommand(groupToAdd, commands, e,
+			   _option->getAsBool(PREF_USE_HEAD));
       _requestGroups.push_back(groupToAdd);
       ++count;
       e->addCommand(commands);
@@ -308,7 +320,8 @@ void RequestGroupMan::getInitialCommands(std::deque<Command*>& commands,
     try {
       if((*itr)->isDependencyResolved()) {
 	configureRequestGroup(*itr);
-	(*itr)->createInitialCommand(commands, e);
+	createInitialCommand(*itr, commands, e,
+			     _option->getAsBool(PREF_USE_HEAD));
 	++itr;
       } else {
 	_reservedGroups.push_front((*itr));

+ 4 - 0
src/option_processing.cc

@@ -189,6 +189,7 @@ Option* option_processing(int argc, char* const argv[])
       { PREF_CA_CERTIFICATE.c_str(), optional_argument, &lopt, 233 },
       { PREF_CHECK_CERTIFICATE.c_str(), optional_argument, &lopt, 234 },
       { PREF_NO_PROXY.c_str(), required_argument, &lopt, 235 },
+      { PREF_USE_HEAD.c_str(), optional_argument, &lopt, 236 },
 #if defined ENABLE_BITTORRENT || defined ENABLE_METALINK
       { PREF_SHOW_FILES.c_str(), no_argument, NULL, 'S' },
       { PREF_SELECT_FILE.c_str(), required_argument, &lopt, 21 },
@@ -470,6 +471,9 @@ Option* option_processing(int argc, char* const argv[])
       case 235:
 	cmdstream << PREF_NO_PROXY << "=" << optarg << "\n";
 	break;
+      case 236:
+	cmdstream << PREF_USE_HEAD << "=" << toBoolArg(optarg) << "\n";
+	break;
       }
       break;
     }

+ 2 - 0
src/prefs.cc

@@ -188,6 +188,8 @@ const std::string PREF_PRIVATE_KEY("private-key");
 const std::string PREF_CA_CERTIFICATE("ca-certificate");
 // value: true | false
 const std::string PREF_CHECK_CERTIFICATE("check-certificate");
+// value: true | false
+const std::string PREF_USE_HEAD("use-head");
 
 /** 
  * Proxy related preferences

+ 2 - 0
src/prefs.h

@@ -192,6 +192,8 @@ extern const std::string PREF_PRIVATE_KEY;
 extern const std::string PREF_CA_CERTIFICATE;
 // value: true | false
 extern const std::string PREF_CHECK_CERTIFICATE;
+// value: true | false
+extern const std::string PREF_USE_HEAD;
 
 /**;
  * Proxy related preferences

+ 3 - 0
src/usage_text.h

@@ -434,3 +434,6 @@ _(" --check-certificate[=true|false] Verify the peer using certificates specifie
 #define TEXT_NO_PROXY \
 _(" --no-proxy=DOMAINS           Specify comma separated hostnames or domains where\n"\
   "                              proxy should not be used.")
+#define TEXT_USE_HEAD \
+_(" --use-head[=true|false]      Use HEAD method for the first request to the HTTP\n"\
+  "                              server.")