diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-04-20 06:30:44 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-04-20 06:30:44 +0000 |
| commit | 3eb74629cbd0f01113bc581d486a8ec95633b4ad (patch) | |
| tree | 53028931fb30d824e2226e6cfef6c51c9863c120 /src | |
| parent | c1c5e7369f77a1125b12ac58b8b30378858d9317 (diff) | |
2008-04-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added --header option. You can specify any number of additional
HTTP headers
like:
aria2 --header="X-A: 300" --header="X-B: 900" http://host/file
Unlike other commad-line option, you can use --header option
multiple times.
* src/HelpItemFactory.cc
* src/HttpRequest.{cc, h}
* src/HttpRequestCommand.cc
* src/OptionHandlerFactory.cc
* src/OptionHandlerImpl.h
* src/option_processing.cc
* src/prefs.h
* src/usage_text.h
* test/HttpRequestTest.cc (testUserHeaders)
Diffstat (limited to 'src')
| -rw-r--r-- | src/HelpItemFactory.cc | 5 | ||||
| -rw-r--r-- | src/HttpRequest.cc | 14 | ||||
| -rw-r--r-- | src/HttpRequest.h | 4 | ||||
| -rw-r--r-- | src/HttpRequestCommand.cc | 1 | ||||
| -rw-r--r-- | src/OptionHandlerFactory.cc | 2 | ||||
| -rw-r--r-- | src/OptionHandlerImpl.h | 19 | ||||
| -rw-r--r-- | src/option_processing.cc | 4 | ||||
| -rw-r--r-- | src/prefs.h | 2 | ||||
| -rw-r--r-- | src/usage_text.h | 6 |
9 files changed, 56 insertions, 1 deletions
diff --git a/src/HelpItemFactory.cc b/src/HelpItemFactory.cc index 5025883f..e4011e06 100644 --- a/src/HelpItemFactory.cc +++ b/src/HelpItemFactory.cc @@ -433,6 +433,11 @@ TagContainerHandle HelpItemFactory::createHelpItems() tc->addItem(item); } { + HelpItemHandle item(new HelpItem(PREF_HEADER, TEXT_HEADER)); + item->addTag(TAG_ADVANCED); + tc->addItem(item); + } + { HelpItemHandle item(new HelpItem("help", TEXT_HELP, TAG_BASIC)); char buf[64]; snprintf(buf, sizeof(buf), "%s,%s,%s,%s,%s,%s,all", TAG_BASIC, TAG_ADVANCED, TAG_HTTP, TAG_FTP, TAG_METALINK, TAG_BITTORRENT); diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 9d43902d..da2db386 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -44,6 +44,7 @@ #include "prefs.h" #include "AuthConfigFactory.h" #include "AuthConfig.h" +#include <numeric> namespace aria2 { @@ -190,6 +191,12 @@ std::string HttpRequest::createRequest() const if(cookiesValue.size()) { requestLine += std::string("Cookie: ")+cookiesValue+"\r\n"; } + // append additional headers given by user. + for(std::deque<std::string>::const_iterator i = _userHeaders.begin(); + i != _userHeaders.end(); ++i) { + requestLine += (*i)+"\r\n"; + } + requestLine += "\r\n"; return requestLine; } @@ -218,6 +225,13 @@ std::string HttpRequest::getProxyAuthString() const { Base64::encode(AuthConfigFactorySingleton::instance()->createAuthConfigForHttpProxy(request)->getAuthText())+"\r\n"; } +void HttpRequest::setUserHeaders(const std::string& userHeadersString) +{ + std::deque<std::string> headers; + Util::slice(headers, userHeadersString, '\n', true); + _userHeaders = headers; +} + void HttpRequest::configure(const Option* option) { authEnabled = option->get(PREF_HTTP_AUTH_ENABLED) == V_TRUE; diff --git a/src/HttpRequest.h b/src/HttpRequest.h index a47b10a3..ae39bb47 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -66,6 +66,8 @@ private: std::string userAgent; + std::deque<std::string> _userHeaders; + std::string getHostText(const std::string& host, uint16_t port) const; std::string getProxyAuthString() const; @@ -164,6 +166,8 @@ public: { this->userAgent = userAgent; } + + void setUserHeaders(const std::string& userHeaders); }; typedef SharedHandle<HttpRequest> HttpRequestHandle; diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc index c691c4b3..7f94c34e 100644 --- a/src/HttpRequestCommand.cc +++ b/src/HttpRequestCommand.cc @@ -84,6 +84,7 @@ bool HttpRequestCommand::executeInternal() { httpRequest->setUserAgent(e->option->get(PREF_USER_AGENT)); httpRequest->setRequest(req); httpRequest->setEntityLength(_requestGroup->getTotalLength()); + httpRequest->setUserHeaders(e->option->get(PREF_HEADER)); httpRequest->configure(e->option); _httpConnection->sendRequest(httpRequest); diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index 9dafed57..a8e0ce3e 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -126,7 +126,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() handlers.push_back(SH(new NumberOptionHandler(PREF_STOP, 0, INT32_MAX))); handlers.push_back(SH(new ParameterOptionHandler(PREF_BT_MIN_CRYPTO_LEVEL, V_PLAIN, V_ARC4))); handlers.push_back(SH(new BooleanOptionHandler(PREF_BT_REQUIRE_CRYPTO))); - + handlers.push_back(SH(new CumulativeOptionHandler(PREF_HEADER, "\n"))); return handlers; } diff --git a/src/OptionHandlerImpl.h b/src/OptionHandlerImpl.h index 5925e3b4..1d6e81a9 100644 --- a/src/OptionHandlerImpl.h +++ b/src/OptionHandlerImpl.h @@ -192,6 +192,25 @@ public: } }; +class CumulativeOptionHandler : public NameMatchOptionHandler { +private: + std::string _delim; +public: + CumulativeOptionHandler(const std::string& optName, + const std::string& delim): + NameMatchOptionHandler(optName), + _delim(delim) {} + + virtual ~CumulativeOptionHandler() {} + + virtual void parseArg(Option* option, const std::string& optarg) + { + std::string value = option->get(_optName); + value += optarg+_delim; + option->put(_optName, value); + } +}; + class ParameterOptionHandler : public NameMatchOptionHandler { private: std::deque<std::string> _validParamValues; diff --git a/src/option_processing.cc b/src/option_processing.cc index 6c11cac1..74cb0044 100644 --- a/src/option_processing.cc +++ b/src/option_processing.cc @@ -204,6 +204,7 @@ Option* option_processing(int argc, char* const argv[]) { PREF_NO_CONF, no_argument, &lopt, 212 }, { PREF_CONF_PATH, required_argument, &lopt, 213 }, { PREF_STOP, required_argument, &lopt, 214 }, + { PREF_HEADER, required_argument, &lopt, 215 }, #if defined ENABLE_BITTORRENT || ENABLE_METALINK { PREF_SHOW_FILES, no_argument, NULL, 'S' }, { PREF_SELECT_FILE, required_argument, &lopt, 21 }, @@ -402,6 +403,9 @@ Option* option_processing(int argc, char* const argv[]) case 214: cmdstream << PREF_STOP << "=" << optarg << "\n"; break; + case 215: + cmdstream << PREF_HEADER << "=" << optarg << "\n"; + break; } break; } diff --git a/src/prefs.h b/src/prefs.h index 88c4fe0f..96c5e351 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -163,6 +163,8 @@ #define PREF_ENABLE_HTTP_PIPELINING "enable-http-pipelining" // value: 1*digit #define PREF_MAX_HTTP_PIPELINING "max-http-pipelining" +// value: string +#define PREF_HEADER "header" /** * HTTP proxy related preferences diff --git a/src/usage_text.h b/src/usage_text.h index 774a2317..af3b1d20 100644 --- a/src/usage_text.h +++ b/src/usage_text.h @@ -330,3 +330,9 @@ _(" --conf-path=PATH Change the configuration file path to PATH.") #define TEXT_STOP \ _(" --stop=SEC Stop application after SEC seconds has passed.\n" \ " If 0 is given, this feature is disabled.") +#define TEXT_HEADER \ +_(" --header=HEADER Append HEADER to HTTP request header. You can use\n"\ + " this option repeatedly to specify more than one\n"\ + " header:\n"\ + " aria2c --header=\"X-A: b78\" --header=\"X-B: 9J1\"\n"\ + " http://host/file") |
