diff --git a/ChangeLog b/ChangeLog index d0175e72..0f954018 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2010-01-10 Tatsuhiro Tsujikawa + + 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 Removed Logger from OptionParser. When OptionParser is used to diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index a053e897..7e9cc051 100644 --- a/src/HttpRequest.cc +++ b/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) @@ -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"; } diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 0635b60b..2ba46a3f 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -83,6 +83,8 @@ private: SharedHandle _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 HttpRequestHandle; diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc index 5183c642..c6148e39 100644 --- a/src/HttpRequestCommand.cc +++ b/src/HttpRequestCommand.cc @@ -96,7 +96,11 @@ createHttpRequest(const SharedHandle& 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; } diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index 5a0f48c8..71fb8e0c 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -707,6 +707,15 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() op->addTag(TAG_HTTP); handlers.push_back(op); } + { + SharedHandle 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 op(new DefaultOptionHandler (PREF_HTTP_PASSWD, diff --git a/src/download_helper.cc b/src/download_helper.cc index 246c2f87..bf02bf19 100644 --- a/src/download_helper.cc +++ b/src/download_helper.cc @@ -89,6 +89,7 @@ const std::set& listRequestOptions() PREF_SPLIT, PREF_TIMEOUT, PREF_HTTP_AUTH_CHALLENGE, + PREF_HTTP_NO_CACHE, PREF_HTTP_USER, PREF_HTTP_PASSWD, PREF_HTTP_PROXY, diff --git a/src/prefs.cc b/src/prefs.cc index 93b8c4be..321ac8f0 100644 --- a/src/prefs.cc +++ b/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 diff --git a/src/prefs.h b/src/prefs.h index 27276463..68d1d9c5 100644 --- a/src/prefs.h +++ b/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 diff --git a/src/usage_text.h b/src/usage_text.h index 5c72d1cf..0f94509e 100644 --- a/src/usage_text.h +++ b/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.")