comma delimeting multiple cors headers (#1078)
This commit is contained in:
parent
effa2cf96d
commit
9b91444638
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -301,7 +301,7 @@ dependencies = [
|
||||
"ethsync 1.2.0",
|
||||
"json-ipc-server 0.1.0 (git+https://github.com/ethcore/json-ipc-server.git)",
|
||||
"jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)",
|
||||
"jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git?branch=multiple_cors_domains)",
|
||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -577,6 +577,16 @@ dependencies = [
|
||||
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jsonrpc-http-server"
|
||||
version = "5.1.0"
|
||||
source = "git+https://github.com/ethcore/jsonrpc-http-server.git?branch=multiple_cors_domains#9c026feeb6573c82c99c8005c5d8244de68a2e30"
|
||||
dependencies = [
|
||||
"hyper 0.9.3 (git+https://github.com/ethcore/hyper)",
|
||||
"jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kernel32-sys"
|
||||
version = "0.2.2"
|
||||
|
@ -263,8 +263,9 @@ impl Configuration {
|
||||
self.args.flag_rpcapi.clone().unwrap_or(self.args.flag_jsonrpc_apis.clone())
|
||||
}
|
||||
|
||||
pub fn rpc_cors(&self) -> Option<String> {
|
||||
self.args.flag_jsonrpc_cors.clone().or(self.args.flag_rpccorsdomain.clone())
|
||||
pub fn rpc_cors(&self) -> Vec<String> {
|
||||
let cors = self.args.flag_jsonrpc_cors.clone().or(self.args.flag_rpccorsdomain.clone());
|
||||
cors.map_or_else(Vec::new, |c| c.split(',').map(|s| s.to_owned()).collect())
|
||||
}
|
||||
|
||||
fn geth_ipc_path() -> &'static str {
|
||||
@ -338,7 +339,7 @@ mod tests {
|
||||
assert_eq!(net.rpc_enabled, true);
|
||||
assert_eq!(net.rpc_interface, "all".to_owned());
|
||||
assert_eq!(net.rpc_port, 8000);
|
||||
assert_eq!(conf.rpc_cors(), Some("*".to_owned()));
|
||||
assert_eq!(conf.rpc_cors(), vec!["*".to_owned()]);
|
||||
assert_eq!(conf.rpc_apis(), "web3,eth".to_owned());
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ pub struct HttpConfiguration {
|
||||
pub interface: String,
|
||||
pub port: u16,
|
||||
pub apis: String,
|
||||
pub cors: Option<String>,
|
||||
pub cors: Vec<String>,
|
||||
}
|
||||
|
||||
pub struct IpcConfiguration {
|
||||
@ -139,11 +139,11 @@ pub fn setup_http_rpc_server(
|
||||
pub fn setup_http_rpc_server(
|
||||
dependencies: &Arc<Dependencies>,
|
||||
url: &SocketAddr,
|
||||
cors_domain: Option<String>,
|
||||
cors_domains: Vec<String>,
|
||||
apis: Vec<&str>,
|
||||
) -> RpcServer {
|
||||
let server = setup_rpc_server(apis, dependencies);
|
||||
let start_result = server.start_http(url, cors_domain);
|
||||
let start_result = server.start_http(url, cors_domains);
|
||||
let deps = dependencies.clone();
|
||||
match start_result {
|
||||
Err(RpcServerError::IoError(err)) => die_with_io_error("RPC", err),
|
||||
|
@ -13,7 +13,7 @@ log = "0.3"
|
||||
serde = "0.7.0"
|
||||
serde_json = "0.7.0"
|
||||
jsonrpc-core = "2.0"
|
||||
jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc-http-server.git" }
|
||||
jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc-http-server.git", branch = "multiple_cors_domains" }
|
||||
ethcore-util = { path = "../util" }
|
||||
ethcore = { path = "../ethcore" }
|
||||
ethash = { path = "../ethash" }
|
||||
|
@ -59,9 +59,11 @@ impl RpcServer {
|
||||
}
|
||||
|
||||
/// Start http server asynchronously and returns result with `Server` handle on success or an error.
|
||||
pub fn start_http(&self, addr: &SocketAddr, cors_domain: Option<String>) -> Result<Server, RpcServerError> {
|
||||
let cors_domain = cors_domain.to_owned();
|
||||
Server::start(addr, self.handler.clone(), cors_domain.map(jsonrpc_http_server::AccessControlAllowOrigin::Value))
|
||||
pub fn start_http(&self, addr: &SocketAddr, cors_domains: Vec<String>) -> Result<Server, RpcServerError> {
|
||||
let cors_domains = cors_domains.into_iter()
|
||||
.map(jsonrpc_http_server::AccessControlAllowOrigin::Value)
|
||||
.collect();
|
||||
Server::start(addr, self.handler.clone(), cors_domains)
|
||||
}
|
||||
|
||||
/// Start ipc server asynchronously and returns result with `Server` handle on success or an error.
|
||||
|
Loading…
Reference in New Issue
Block a user