Skip to content

Commit

Permalink
Merge pull request #546 from rkusa/cors-for-errors
Browse files Browse the repository at this point in the history
Add CORS headers to error responses
  • Loading branch information
yoshuawuyts authored Jul 15, 2020
2 parents ba65ca4 + 7b30442 commit be1c3a9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/security/cors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,20 @@ mod test {

assert_eq!(res[http_types::headers::SET_COOKIE][0], "foo=bar");
}

#[async_std::test]
async fn set_cors_headers_to_error_responses() {
let mut app = crate::Server::new();
app.at(ENDPOINT).get(|_| async {
Err::<&str, _>(crate::Error::from_str(
StatusCode::BadRequest,
"bad request",
))
});
app.middleware(CorsMiddleware::new().allow_origin(Origin::from(ALLOW_ORIGIN)));

let res: crate::http::Response = app.respond(request()).await.unwrap();
assert_eq!(res.status(), 400);
assert_eq!(res[headers::ACCESS_CONTROL_ALLOW_ORIGIN], ALLOW_ORIGIN);
}
}

0 comments on commit be1c3a9

Please sign in to comment.