mirror of
https://github.com/actix/actix-web.git
synced 2025-01-09 08:45:29 +00:00
CORS middleware: allowed_headers is defaulting to None #50
This commit is contained in:
parent
867bb1d409
commit
71d534dadb
4 changed files with 15 additions and 18 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
* Can't have multiple Applications on a single server with different state #49
|
* Can't have multiple Applications on a single server with different state #49
|
||||||
|
|
||||||
|
* CORS middleware: allowed_headers is defaulting to None #50
|
||||||
|
|
||||||
## 0.3.1 (2018-01-13)
|
## 0.3.1 (2018-01-13)
|
||||||
|
|
||||||
|
|
|
@ -423,8 +423,8 @@ impl HttpResponseBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method calls provided closure with builder reference if value is Some.
|
/// This method calls provided closure with builder reference if value is Some.
|
||||||
pub fn if_some<T, F>(&mut self, value: Option<&T>, f: F) -> &mut Self
|
pub fn if_some<T, F>(&mut self, value: Option<T>, f: F) -> &mut Self
|
||||||
where F: FnOnce(&T, &mut HttpResponseBuilder)
|
where F: FnOnce(T, &mut HttpResponseBuilder)
|
||||||
{
|
{
|
||||||
if let Some(val) = value {
|
if let Some(val) = value {
|
||||||
f(val, self);
|
f(val, self);
|
||||||
|
|
|
@ -295,16 +295,23 @@ impl<S> Middleware<S> for Cors {
|
||||||
self.validate_allowed_method(req)?;
|
self.validate_allowed_method(req)?;
|
||||||
self.validate_allowed_headers(req)?;
|
self.validate_allowed_headers(req)?;
|
||||||
|
|
||||||
|
// allowed headers
|
||||||
|
let headers = if let Some(headers) = self.headers.as_ref() {
|
||||||
|
Some(HeaderValue::try_from(&headers.iter().fold(
|
||||||
|
String::new(), |s, v| s + "," + v.as_str()).as_str()[1..]).unwrap())
|
||||||
|
} else if let Some(hdr) = req.headers().get(header::ACCESS_CONTROL_REQUEST_HEADERS) {
|
||||||
|
Some(hdr.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Started::Response(
|
Ok(Started::Response(
|
||||||
HTTPOk.build()
|
HTTPOk.build()
|
||||||
.if_some(self.max_age.as_ref(), |max_age, resp| {
|
.if_some(self.max_age.as_ref(), |max_age, resp| {
|
||||||
let _ = resp.header(
|
let _ = resp.header(
|
||||||
header::ACCESS_CONTROL_MAX_AGE, format!("{}", max_age).as_str());})
|
header::ACCESS_CONTROL_MAX_AGE, format!("{}", max_age).as_str());})
|
||||||
.if_some(self.headers.as_ref(), |headers, resp| {
|
.if_some(headers, |headers, resp| {
|
||||||
let _ = resp.header(
|
let _ = resp.header(header::ACCESS_CONTROL_ALLOW_HEADERS, headers); })
|
||||||
header::ACCESS_CONTROL_ALLOW_HEADERS,
|
|
||||||
&headers.iter().fold(
|
|
||||||
String::new(), |s, v| s + "," + v.as_str()).as_str()[1..]);})
|
|
||||||
.if_true(self.origins.is_all(), |resp| {
|
.if_true(self.origins.is_all(), |resp| {
|
||||||
if self.send_wildcard {
|
if self.send_wildcard {
|
||||||
resp.header(header::ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
resp.header(header::ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
||||||
|
|
|
@ -1201,17 +1201,6 @@ mod tests {
|
||||||
} else {
|
} else {
|
||||||
panic!("Error");
|
panic!("Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buf = Buffer::new(
|
|
||||||
"GET /test HTTP/1.1\r\n\
|
|
||||||
transfer-encoding: chunked\r\n\r\n");
|
|
||||||
let req = parse_ready!(&mut buf);
|
|
||||||
|
|
||||||
if let Ok(val) = req.chunked() {
|
|
||||||
assert!(!val);
|
|
||||||
} else {
|
|
||||||
panic!("Error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue