Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Echo CORS request headers by default (#10221)
Browse files Browse the repository at this point in the history
* Echo CORS request headers by default

More details in #6616.

* fixup: Single line
  • Loading branch information
cmichi authored and ascjones committed Jan 21, 2019
1 parent 708e495 commit 940a88f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ethcore/res/ethereum/tests
Submodule tests updated 110 files
4 changes: 3 additions & 1 deletion rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub use ipc::{Server as IpcServer, MetaExtractor as IpcMetaExtractor, RequestCon
pub use http::{
hyper,
RequestMiddleware, RequestMiddlewareAction,
AccessControlAllowOrigin, Host, DomainsValidation
AccessControlAllowOrigin, Host, DomainsValidation, cors::AccessControlAllowHeaders
};

pub use v1::{NetworkSettings, Metadata, Origin, informant, dispatch, signer};
Expand Down Expand Up @@ -151,6 +151,7 @@ pub fn start_http<M, S, H, T>(
.cors(cors_domains.into())
.allowed_hosts(allowed_hosts.into())
.health_api(("/api/health", "parity_nodeStatus"))
.cors_allow_headers(AccessControlAllowHeaders::Any)
.max_request_body_size(max_payload * 1024 * 1024)
.start_http(addr)?)
}
Expand Down Expand Up @@ -180,6 +181,7 @@ pub fn start_http_with_middleware<M, S, H, T, R>(
.threads(threads)
.cors(cors_domains.into())
.allowed_hosts(allowed_hosts.into())
.cors_allow_headers(AccessControlAllowHeaders::Any)
.max_request_body_size(max_payload * 1024 * 1024)
.request_middleware(middleware)
.start_http(addr)?)
Expand Down
27 changes: 27 additions & 0 deletions rpc/src/tests/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,31 @@ mod tests {
res.assert_status("HTTP/1.1 200 OK");
assert_eq!(res.body, expected);
}

#[test]
fn should_respond_valid_to_any_requested_header() {
// given
let (server, address) = serve();
let headers = "Something, Anything, Xyz, 123, _?";

// when
let res = request(server,
&format!("\
OPTIONS / HTTP/1.1\r\n\
Host: {}\r\n\
Origin: http://parity.io\r\n\
Content-Length: 0\r\n\
Content-Type: application/json\r\n\
Connection: close\r\n\
Access-Control-Request-Headers: {}\r\n\
\r\n\
", address, headers)
);

// then
assert_eq!(res.status, "HTTP/1.1 200 OK".to_owned());
let expected = format!("access-control-allow-headers: {}", headers);
assert!(res.headers.contains(&expected), "Headers missing in {:?}", res.headers);
}

}

0 comments on commit 940a88f

Please sign in to comment.