diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-08-18 21:22:48 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-08-18 21:24:18 +0900 |
| commit | 384ef111b90b7bcb04b8ff477eca7218a99cb98d (patch) | |
| tree | ab6627f0f2f15d98f78f3ad0e83c703fad871161 /src | |
| parent | 4c1c38a33f669ce09fe9b6cd046b270cf70253ac (diff) | |
Added --rpc-allow-origin-all option.
This option adds Access-Control-Allow-Origin header field with value
'*' to the RPC response.
Diffstat (limited to 'src')
| -rw-r--r-- | src/HttpServer.cc | 3 | ||||
| -rw-r--r-- | src/HttpServer.h | 6 | ||||
| -rw-r--r-- | src/HttpServerCommand.cc | 3 | ||||
| -rw-r--r-- | src/OptionHandlerFactory.cc | 9 | ||||
| -rw-r--r-- | src/prefs.cc | 2 | ||||
| -rw-r--r-- | src/prefs.h | 2 | ||||
| -rw-r--r-- | src/usage_text.h | 3 |
7 files changed, 28 insertions, 0 deletions
diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 31893c95..9d3eaaa7 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -165,6 +165,9 @@ void HttpServer::feedResponse(const std::string& status, strappend(header, "Content-Length: ", util::uitos(text.size()), "\r\n", "Expires: ", httpDate, "\r\n", "Cache-Control: no-cache\r\n"); + if(!allowOrigin_.empty()) { + strappend(header, "Access-Control-Allow-Origin: ", allowOrigin_, "\r\n"); + } if(supportsGZip()) { header += "Content-Encoding: gzip\r\n"; } diff --git a/src/HttpServer.h b/src/HttpServer.h index 2f8d6329..c8dbc8c2 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -68,6 +68,7 @@ private: std::string password_; bool acceptsPersistentConnection_; bool acceptsGZip_; + std::string allowOrigin_; public: HttpServer(const SharedHandle<SocketCore>& socket, DownloadEngine* e); @@ -123,6 +124,11 @@ public: { return socketRecvBuffer_; } + + void setAllowOrigin(const std::string& allowOrigin) + { + allowOrigin_ = allowOrigin; + } }; } // namespace aria2 diff --git a/src/HttpServerCommand.cc b/src/HttpServerCommand.cc index 8306ad15..4dd43a7c 100644 --- a/src/HttpServerCommand.cc +++ b/src/HttpServerCommand.cc @@ -66,6 +66,9 @@ HttpServerCommand::HttpServerCommand e_->addSocketForReadCheck(socket_, this); httpServer_->setUsernamePassword(e_->getOption()->get(PREF_RPC_USER), e_->getOption()->get(PREF_RPC_PASSWD)); + if(e_->getOption()->getAsBool(PREF_RPC_ALLOW_ORIGIN_ALL)) { + httpServer_->setAllowOrigin("*"); + } #ifdef HAVE_ZLIB httpServer_->enableGZip(); #else // !HAVE_ZLIB diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index ae2db34a..87fd87b5 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -597,6 +597,15 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() } { SharedHandle<OptionHandler> op(new BooleanOptionHandler + (PREF_RPC_ALLOW_ORIGIN_ALL, + TEXT_RPC_ALLOW_ORIGIN_ALL, + A2_V_FALSE, + OptionHandler::OPT_ARG)); + op->addTag(TAG_RPC); + handlers.push_back(op); + } + { + SharedHandle<OptionHandler> op(new BooleanOptionHandler (PREF_RPC_LISTEN_ALL, TEXT_RPC_LISTEN_ALL, A2_V_FALSE, diff --git a/src/prefs.cc b/src/prefs.cc index f8407198..ad7583c0 100644 --- a/src/prefs.cc +++ b/src/prefs.cc @@ -169,6 +169,8 @@ const std::string PREF_RPC_MAX_REQUEST_SIZE("rpc-max-request-size"); // value: true | false const std::string PREF_RPC_LISTEN_ALL("rpc-listen-all"); // value: true | false +const std::string PREF_RPC_ALLOW_ORIGIN_ALL("rpc-allow-origin-all"); +// value: true | false const std::string PREF_ENABLE_XML_RPC("enable-xml-rpc"); // value: 1*digit const std::string PREF_XML_RPC_LISTEN_PORT("xml-rpc-listen-port"); diff --git a/src/prefs.h b/src/prefs.h index 18ab9cb5..373ac695 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -172,6 +172,8 @@ extern const std::string PREF_RPC_MAX_REQUEST_SIZE; // value: true | false extern const std::string PREF_RPC_LISTEN_ALL; // value: true | false +extern const std::string PREF_RPC_ALLOW_ORIGIN_ALL; +// value: true | false extern const std::string PREF_ENABLE_XML_RPC; // value: 1*digit extern const std::string PREF_XML_RPC_LISTEN_PORT; diff --git a/src/usage_text.h b/src/usage_text.h index 7e5d1316..c505b124 100644 --- a/src/usage_text.h +++ b/src/usage_text.h @@ -816,3 +816,6 @@ #define TEXT_PAUSE \ _(" --pause[=true|false] Pause download after added. This option is\n" \ " effective only when --enable-rpc=true is given.") +#define TEXT_RPC_ALLOW_ORIGIN_ALL \ + _(" --rpc-allow-origin-all[=true|false] Add Access-Control-Allow-Origin header\n" \ + " field with value '*' to the RPC response.") |
