瀏覽代碼

2010-01-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Added --http-no-cache option.  When true is given, aria2 sends
	Cache-Control: no-cache and Pragma: no-cache header to avoid
	cached content.  If false is given , these headers are not sent
	and you can add Cache-Control header with a directive you like
	using --header option.
	* src/HttpRequest.cc
	* src/HttpRequest.h
	* src/HttpRequestCommand.cc
	* src/OptionHandlerFactory.cc
	* src/download_helper.cc
	* src/prefs.cc
	* src/prefs.h
	* src/usage_text.h
Tatsuhiro Tsujikawa 15 年之前
父節點
當前提交
658442b762
共有 9 個文件被更改,包括 59 次插入5 次删除
  1. 16 0
      ChangeLog
  2. 6 4
      src/HttpRequest.cc
  3. 12 0
      src/HttpRequest.h
  4. 5 1
      src/HttpRequestCommand.cc
  5. 9 0
      src/OptionHandlerFactory.cc
  6. 1 0
      src/download_helper.cc
  7. 2 0
      src/prefs.cc
  8. 2 0
      src/prefs.h
  9. 6 0
      src/usage_text.h

+ 16 - 0
ChangeLog

@@ -1,3 +1,19 @@
+2010-01-10  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Added --http-no-cache option.  When true is given, aria2 sends
+	Cache-Control: no-cache and Pragma: no-cache header to avoid
+	cached content.  If false is given , these headers are not sent
+	and you can add Cache-Control header with a directive you like
+	using --header option.
+	* src/HttpRequest.cc
+	* src/HttpRequest.h
+	* src/HttpRequestCommand.cc
+	* src/OptionHandlerFactory.cc
+	* src/download_helper.cc
+	* src/prefs.cc
+	* src/prefs.h
+	* src/usage_text.h
+
 2010-01-10  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Removed Logger from OptionParser. When OptionParser is used to

+ 6 - 4
src/HttpRequest.cc

@@ -55,7 +55,8 @@ namespace aria2 {
 const std::string HttpRequest::USER_AGENT("aria2");
 
 HttpRequest::HttpRequest():_contentEncodingEnabled(true),
-                           userAgent(USER_AGENT)
+                           userAgent(USER_AGENT),
+                           _noCache(true)
 {}
 
 void HttpRequest::setSegment(const SharedHandle<Segment>& segment)
@@ -174,9 +175,10 @@ std::string HttpRequest::createRequest()
   }
 
   strappend(requestLine, "Host: ", getHostText(getURIHost(), getPort()), "\r\n");
-  requestLine += "Pragma: no-cache\r\n";
-  requestLine += "Cache-Control: no-cache\r\n";
-
+  if(_noCache) {
+    requestLine += "Pragma: no-cache\r\n";
+    requestLine += "Cache-Control: no-cache\r\n";
+  }
   if(!request->isKeepAliveEnabled() && !request->isPipeliningEnabled()) {
     requestLine += "Connection: close\r\n";
   }

+ 12 - 0
src/HttpRequest.h

@@ -83,6 +83,8 @@ private:
 
   SharedHandle<Request> _proxyRequest;
 
+  bool _noCache;
+
   std::string getProxyAuthString() const;
 public:
   HttpRequest();
@@ -243,6 +245,16 @@ public:
   {
     return _fileEntry;
   }
+
+  void enableNoCache()
+  {
+    _noCache = true;
+  }
+
+  void disableNoCache()
+  {
+    _noCache = false;
+  }
 };
 
 typedef SharedHandle<HttpRequest> HttpRequestHandle;

+ 5 - 1
src/HttpRequestCommand.cc

@@ -96,7 +96,11 @@ createHttpRequest(const SharedHandle<Request>& req,
   httpRequest->setProxyRequest(proxyRequest);
   httpRequest->addAcceptType(rg->getAcceptTypes().begin(),
                              rg->getAcceptTypes().end());
-
+  if(option->getAsBool(PREF_HTTP_NO_CACHE)) {
+    httpRequest->enableNoCache();
+  } else {
+    httpRequest->disableNoCache();
+  }
   return httpRequest;
 }
 

+ 9 - 0
src/OptionHandlerFactory.cc

@@ -707,6 +707,15 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
     op->addTag(TAG_HTTP);
     handlers.push_back(op);
   }
+  {
+    SharedHandle<OptionHandler> op(new BooleanOptionHandler
+                                   (PREF_HTTP_NO_CACHE,
+                                    TEXT_HTTP_NO_CACHE,
+                                    V_TRUE,
+                                    OptionHandler::OPT_ARG));
+    op->addTag(TAG_HTTP);
+    handlers.push_back(op);
+  }
   {
     SharedHandle<OptionHandler> op(new DefaultOptionHandler
                                    (PREF_HTTP_PASSWD,

+ 1 - 0
src/download_helper.cc

@@ -89,6 +89,7 @@ const std::set<std::string>& listRequestOptions()
     PREF_SPLIT,
     PREF_TIMEOUT,
     PREF_HTTP_AUTH_CHALLENGE,
+    PREF_HTTP_NO_CACHE,
     PREF_HTTP_USER,
     PREF_HTTP_PASSWD,
     PREF_HTTP_PROXY,

+ 2 - 0
src/prefs.cc

@@ -222,6 +222,8 @@ const std::string PREF_CHECK_CERTIFICATE("check-certificate");
 const std::string PREF_USE_HEAD("use-head");
 // value: true | false
 const std::string PREF_HTTP_AUTH_CHALLENGE("http-auth-challenge");
+// value: true | false
+const std::string PREF_HTTP_NO_CACHE("http-no-cache");
 
 /** 
  * Proxy related preferences

+ 2 - 0
src/prefs.h

@@ -226,6 +226,8 @@ extern const std::string PREF_CHECK_CERTIFICATE;
 extern const std::string PREF_USE_HEAD;
 // value: true | false
 extern const std::string PREF_HTTP_AUTH_CHALLENGE;
+// value: true | false
+extern const std::string PREF_HTTP_NO_CACHE;
 
 /**;
  * Proxy related preferences

+ 6 - 0
src/usage_text.h

@@ -590,3 +590,9 @@
     "                              .torrent. The directory to be saved is the same\n" \
     "                              directory where download file is saved. If the\n" \
     "                              same file already exists, metadata is not saved.")
+#define TEXT_HTTP_NO_CACHE                      \
+  _(" --http-no-cache[=true|false] Send Cache-Control: no-cache and Pragma: no-cache\n" \
+    "                              header to avoid cached content.  If false is given\n" \
+    "                              , these headers are not sent and you can add\n" \
+    "                              Cache-Control header with a directive you like\n" \
+    "                              using --header option.")