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

Commit 940a88f

Browse files
cmichiascjones
authored andcommitted
Echo CORS request headers by default (#10221)
* Echo CORS request headers by default More details in #6616. * fixup: Single line
1 parent 708e495 commit 940a88f

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

ethcore/res/ethereum/tests

Submodule tests updated 110 files

rpc/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub use ipc::{Server as IpcServer, MetaExtractor as IpcMetaExtractor, RequestCon
114114
pub use http::{
115115
hyper,
116116
RequestMiddleware, RequestMiddlewareAction,
117-
AccessControlAllowOrigin, Host, DomainsValidation
117+
AccessControlAllowOrigin, Host, DomainsValidation, cors::AccessControlAllowHeaders
118118
};
119119

120120
pub use v1::{NetworkSettings, Metadata, Origin, informant, dispatch, signer};
@@ -151,6 +151,7 @@ pub fn start_http<M, S, H, T>(
151151
.cors(cors_domains.into())
152152
.allowed_hosts(allowed_hosts.into())
153153
.health_api(("/api/health", "parity_nodeStatus"))
154+
.cors_allow_headers(AccessControlAllowHeaders::Any)
154155
.max_request_body_size(max_payload * 1024 * 1024)
155156
.start_http(addr)?)
156157
}
@@ -180,6 +181,7 @@ pub fn start_http_with_middleware<M, S, H, T, R>(
180181
.threads(threads)
181182
.cors(cors_domains.into())
182183
.allowed_hosts(allowed_hosts.into())
184+
.cors_allow_headers(AccessControlAllowHeaders::Any)
183185
.max_request_body_size(max_payload * 1024 * 1024)
184186
.request_middleware(middleware)
185187
.start_http(addr)?)

rpc/src/tests/rpc.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,31 @@ mod tests {
116116
res.assert_status("HTTP/1.1 200 OK");
117117
assert_eq!(res.body, expected);
118118
}
119+
120+
#[test]
121+
fn should_respond_valid_to_any_requested_header() {
122+
// given
123+
let (server, address) = serve();
124+
let headers = "Something, Anything, Xyz, 123, _?";
125+
126+
// when
127+
let res = request(server,
128+
&format!("\
129+
OPTIONS / HTTP/1.1\r\n\
130+
Host: {}\r\n\
131+
Origin: http://parity.io\r\n\
132+
Content-Length: 0\r\n\
133+
Content-Type: application/json\r\n\
134+
Connection: close\r\n\
135+
Access-Control-Request-Headers: {}\r\n\
136+
\r\n\
137+
", address, headers)
138+
);
139+
140+
// then
141+
assert_eq!(res.status, "HTTP/1.1 200 OK".to_owned());
142+
let expected = format!("access-control-allow-headers: {}", headers);
143+
assert!(res.headers.contains(&expected), "Headers missing in {:?}", res.headers);
144+
}
145+
119146
}

0 commit comments

Comments
 (0)