mirror of https://github.com/aria2/aria2
Added --rpc-allow-origin-all option.
This option adds Access-Control-Allow-Origin header field with value '*' to the RPC response.pull/2/head
parent
4c1c38a33f
commit
384ef111b9
|
@ -165,6 +165,9 @@ void HttpServer::feedResponse(const std::string& status,
|
||||||
strappend(header, "Content-Length: ", util::uitos(text.size()), "\r\n",
|
strappend(header, "Content-Length: ", util::uitos(text.size()), "\r\n",
|
||||||
"Expires: ", httpDate, "\r\n",
|
"Expires: ", httpDate, "\r\n",
|
||||||
"Cache-Control: no-cache\r\n");
|
"Cache-Control: no-cache\r\n");
|
||||||
|
if(!allowOrigin_.empty()) {
|
||||||
|
strappend(header, "Access-Control-Allow-Origin: ", allowOrigin_, "\r\n");
|
||||||
|
}
|
||||||
if(supportsGZip()) {
|
if(supportsGZip()) {
|
||||||
header += "Content-Encoding: gzip\r\n";
|
header += "Content-Encoding: gzip\r\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ private:
|
||||||
std::string password_;
|
std::string password_;
|
||||||
bool acceptsPersistentConnection_;
|
bool acceptsPersistentConnection_;
|
||||||
bool acceptsGZip_;
|
bool acceptsGZip_;
|
||||||
|
std::string allowOrigin_;
|
||||||
public:
|
public:
|
||||||
HttpServer(const SharedHandle<SocketCore>& socket, DownloadEngine* e);
|
HttpServer(const SharedHandle<SocketCore>& socket, DownloadEngine* e);
|
||||||
|
|
||||||
|
@ -123,6 +124,11 @@ public:
|
||||||
{
|
{
|
||||||
return socketRecvBuffer_;
|
return socketRecvBuffer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setAllowOrigin(const std::string& allowOrigin)
|
||||||
|
{
|
||||||
|
allowOrigin_ = allowOrigin;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -66,6 +66,9 @@ HttpServerCommand::HttpServerCommand
|
||||||
e_->addSocketForReadCheck(socket_, this);
|
e_->addSocketForReadCheck(socket_, this);
|
||||||
httpServer_->setUsernamePassword(e_->getOption()->get(PREF_RPC_USER),
|
httpServer_->setUsernamePassword(e_->getOption()->get(PREF_RPC_USER),
|
||||||
e_->getOption()->get(PREF_RPC_PASSWD));
|
e_->getOption()->get(PREF_RPC_PASSWD));
|
||||||
|
if(e_->getOption()->getAsBool(PREF_RPC_ALLOW_ORIGIN_ALL)) {
|
||||||
|
httpServer_->setAllowOrigin("*");
|
||||||
|
}
|
||||||
#ifdef HAVE_ZLIB
|
#ifdef HAVE_ZLIB
|
||||||
httpServer_->enableGZip();
|
httpServer_->enableGZip();
|
||||||
#else // !HAVE_ZLIB
|
#else // !HAVE_ZLIB
|
||||||
|
|
|
@ -595,6 +595,15 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
op->addTag(TAG_ADVANCED);
|
op->addTag(TAG_ADVANCED);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
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
|
SharedHandle<OptionHandler> op(new BooleanOptionHandler
|
||||||
(PREF_RPC_LISTEN_ALL,
|
(PREF_RPC_LISTEN_ALL,
|
||||||
|
|
|
@ -169,6 +169,8 @@ const std::string PREF_RPC_MAX_REQUEST_SIZE("rpc-max-request-size");
|
||||||
// value: true | false
|
// value: true | false
|
||||||
const std::string PREF_RPC_LISTEN_ALL("rpc-listen-all");
|
const std::string PREF_RPC_LISTEN_ALL("rpc-listen-all");
|
||||||
// value: true | false
|
// 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");
|
const std::string PREF_ENABLE_XML_RPC("enable-xml-rpc");
|
||||||
// value: 1*digit
|
// value: 1*digit
|
||||||
const std::string PREF_XML_RPC_LISTEN_PORT("xml-rpc-listen-port");
|
const std::string PREF_XML_RPC_LISTEN_PORT("xml-rpc-listen-port");
|
||||||
|
|
|
@ -172,6 +172,8 @@ extern const std::string PREF_RPC_MAX_REQUEST_SIZE;
|
||||||
// value: true | false
|
// value: true | false
|
||||||
extern const std::string PREF_RPC_LISTEN_ALL;
|
extern const std::string PREF_RPC_LISTEN_ALL;
|
||||||
// value: true | false
|
// value: true | false
|
||||||
|
extern const std::string PREF_RPC_ALLOW_ORIGIN_ALL;
|
||||||
|
// value: true | false
|
||||||
extern const std::string PREF_ENABLE_XML_RPC;
|
extern const std::string PREF_ENABLE_XML_RPC;
|
||||||
// value: 1*digit
|
// value: 1*digit
|
||||||
extern const std::string PREF_XML_RPC_LISTEN_PORT;
|
extern const std::string PREF_XML_RPC_LISTEN_PORT;
|
||||||
|
|
|
@ -816,3 +816,6 @@
|
||||||
#define TEXT_PAUSE \
|
#define TEXT_PAUSE \
|
||||||
_(" --pause[=true|false] Pause download after added. This option is\n" \
|
_(" --pause[=true|false] Pause download after added. This option is\n" \
|
||||||
" effective only when --enable-rpc=true is given.")
|
" 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.")
|
||||||
|
|
Loading…
Reference in New Issue