Changing cors header to be optional

This commit is contained in:
Tomasz Drwięga 2016-04-14 14:12:04 +02:00
parent 01e7d2d872
commit 5b2d726a02
3 changed files with 9 additions and 10 deletions

2
Cargo.lock generated
View File

@ -538,7 +538,7 @@ dependencies = [
[[package]] [[package]]
name = "jsonrpc-http-server" name = "jsonrpc-http-server"
version = "5.0.1" version = "5.0.1"
source = "git+https://github.com/debris/jsonrpc-http-server.git#239066b94660a1af24c8b2efc16e800f9c7cce18" source = "git+https://github.com/debris/jsonrpc-http-server.git#054b9b92b0c209b25a92e382b40a240818e4810a"
dependencies = [ dependencies = [
"hyper 0.9.0-mio (git+https://github.com/hyperium/hyper?branch=mio)", "hyper 0.9.0-mio (git+https://github.com/hyperium/hyper?branch=mio)",
"jsonrpc-core 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -133,8 +133,7 @@ API and Console Options:
--jsonrpc-interface IP Specify the hostname portion of the JSONRPC API --jsonrpc-interface IP Specify the hostname portion of the JSONRPC API
server, IP should be an interface's IP address, or server, IP should be an interface's IP address, or
all (all interfaces) or local [default: local]. all (all interfaces) or local [default: local].
--jsonrpc-cors URL Specify CORS header for JSON-RPC API responses --jsonrpc-cors URL Specify CORS header for JSON-RPC API responses.
[default: null].
--jsonrpc-apis APIS Specify the APIs available through the JSONRPC --jsonrpc-apis APIS Specify the APIs available through the JSONRPC
interface. APIS is a comma-delimited list of API interface. APIS is a comma-delimited list of API
name. Possible name are web3, eth and net. name. Possible name are web3, eth and net.
@ -242,7 +241,7 @@ struct Args {
flag_jsonrpc: bool, flag_jsonrpc: bool,
flag_jsonrpc_interface: String, flag_jsonrpc_interface: String,
flag_jsonrpc_port: u16, flag_jsonrpc_port: u16,
flag_jsonrpc_cors: String, flag_jsonrpc_cors: Option<String>,
flag_jsonrpc_apis: String, flag_jsonrpc_apis: String,
flag_webapp: bool, flag_webapp: bool,
flag_webapp_port: u16, flag_webapp_port: u16,
@ -307,7 +306,7 @@ fn setup_rpc_server(
secret_store: Arc<AccountService>, secret_store: Arc<AccountService>,
miner: Arc<Miner>, miner: Arc<Miner>,
url: &SocketAddr, url: &SocketAddr,
cors_domain: &str, cors_domain: Option<String>,
apis: Vec<&str>, apis: Vec<&str>,
) -> RpcServer { ) -> RpcServer {
use rpc::v1::*; use rpc::v1::*;
@ -380,7 +379,7 @@ fn setup_rpc_server(
_secret_store: Arc<AccountService>, _secret_store: Arc<AccountService>,
_miner: Arc<Miner>, _miner: Arc<Miner>,
_url: &str, _url: &str,
_cors_domain: &str, _cors_domain: Option<String>,
_apis: Vec<&str>, _apis: Vec<&str>,
) -> ! { ) -> ! {
die!("Your Parity version has been compiled without JSON-RPC support.") die!("Your Parity version has been compiled without JSON-RPC support.")
@ -713,7 +712,7 @@ impl Configuration {
self.args.flag_rpcport.unwrap_or(self.args.flag_jsonrpc_port) self.args.flag_rpcport.unwrap_or(self.args.flag_jsonrpc_port)
); );
let addr = SocketAddr::from_str(&url).unwrap_or_else(|_| die!("{}: Invalid JSONRPC listen host/port given.", url)); let addr = SocketAddr::from_str(&url).unwrap_or_else(|_| die!("{}: Invalid JSONRPC listen host/port given.", url));
let cors_domain = self.args.flag_rpccorsdomain.as_ref().unwrap_or(&self.args.flag_jsonrpc_cors); let cors_domain = self.args.flag_jsonrpc_cors.clone().or(self.args.flag_rpccorsdomain.clone());
Some(setup_rpc_server( Some(setup_rpc_server(
service.client(), service.client(),
@ -721,7 +720,7 @@ impl Configuration {
account_service.clone(), account_service.clone(),
miner.clone(), miner.clone(),
&addr, &addr,
&cors_domain, cors_domain,
apis.split(',').collect() apis.split(',').collect()
)) ))
} else { } else {

View File

@ -58,8 +58,8 @@ impl RpcServer {
} }
/// Start server asynchronously and returns result with `Server` handle on success or an error. /// Start server asynchronously and returns result with `Server` handle on success or an error.
pub fn start_http(&self, addr: &SocketAddr, cors_domain: &str) -> Result<Server, RpcServerError> { pub fn start_http(&self, addr: &SocketAddr, cors_domain: Option<String>) -> Result<Server, RpcServerError> {
let cors_domain = cors_domain.to_owned(); let cors_domain = cors_domain.to_owned();
Server::start(addr, self.handler.clone(), jsonrpc_http_server::AccessControlAllowOrigin::Value(cors_domain)) Server::start(addr, self.handler.clone(), cors_domain.map(jsonrpc_http_server::AccessControlAllowOrigin::Value))
} }
} }