@@ -134,11 +134,11 @@ Rocket's [managed state](https://rocket.rs/guide/state/#managed-state).
134
134
verb.
135
135
- Then in all the routes you want to enforce CORS on, add a
136
136
[Request Guard](https://rocket.rs/guide/requests/#request-guards) for the
137
- [`Guard`](Guard) struct in the route arguments. You should not wrap this in an
137
+ [`Guard`] struct in the route arguments. You should not wrap this in an
138
138
`Option` or `Result` because the guard will let non-CORS requests through and will take over
139
139
error handling in case of errors.
140
140
- In your routes, to add CORS headers to your responses, use the appropriate functions on the
141
- [`Guard`](Guard) for a `Response` or a `Responder`.
141
+ [`Guard`] for a `Response` or a `Responder`.
142
142
143
143
Refer to the [example](https://github.com/lawliet89/rocket_cors/blob/master/examples/guard.rs).
144
144
@@ -1515,13 +1515,13 @@ impl<'r> FromRequest<'r> for Guard<'r> {
1515
1515
Outcome :: Success ( options) => options,
1516
1516
_ => {
1517
1517
let error = Error :: MissingCorsInRocketState ;
1518
- return Outcome :: Failure ( ( error. status ( ) , error) ) ;
1518
+ return Outcome :: Error ( ( error. status ( ) , error) ) ;
1519
1519
}
1520
1520
} ;
1521
1521
1522
1522
match Response :: validate_and_build ( options, request) {
1523
1523
Ok ( response) => Outcome :: Success ( Self :: new ( response) ) ,
1524
- Err ( error) => Outcome :: Failure ( ( error. status ( ) , error) ) ,
1524
+ Err ( error) => Outcome :: Error ( ( error. status ( ) , error) ) ,
1525
1525
}
1526
1526
}
1527
1527
}
@@ -1757,27 +1757,27 @@ fn validate_allowed_headers(
1757
1757
/// Gets the `Origin` request header from the request
1758
1758
fn origin ( request : & Request < ' _ > ) -> Result < Option < Origin > , Error > {
1759
1759
match Origin :: from_request_sync ( request) {
1760
- Outcome :: Forward ( ( ) ) => Ok ( None ) ,
1760
+ Outcome :: Forward ( _ ) => Ok ( None ) ,
1761
1761
Outcome :: Success ( origin) => Ok ( Some ( origin) ) ,
1762
- Outcome :: Failure ( ( _, err) ) => Err ( err) ,
1762
+ Outcome :: Error ( ( _, err) ) => Err ( err) ,
1763
1763
}
1764
1764
}
1765
1765
1766
1766
/// Gets the `Access-Control-Request-Method` request header from the request
1767
1767
fn request_method ( request : & Request < ' _ > ) -> Result < Option < AccessControlRequestMethod > , Error > {
1768
1768
match AccessControlRequestMethod :: from_request_sync ( request) {
1769
- Outcome :: Forward ( ( ) ) => Ok ( None ) ,
1769
+ Outcome :: Forward ( _ ) => Ok ( None ) ,
1770
1770
Outcome :: Success ( method) => Ok ( Some ( method) ) ,
1771
- Outcome :: Failure ( ( _, err) ) => Err ( err) ,
1771
+ Outcome :: Error ( ( _, err) ) => Err ( err) ,
1772
1772
}
1773
1773
}
1774
1774
1775
1775
/// Gets the `Access-Control-Request-Headers` request header from the request
1776
1776
fn request_headers ( request : & Request < ' _ > ) -> Result < Option < AccessControlRequestHeaders > , Error > {
1777
1777
match AccessControlRequestHeaders :: from_request_sync ( request) {
1778
- Outcome :: Forward ( ( ) ) => Ok ( None ) ,
1778
+ Outcome :: Forward ( _ ) => Ok ( None ) ,
1779
1779
Outcome :: Success ( geaders) => Ok ( Some ( geaders) ) ,
1780
- Outcome :: Failure ( ( _, err) ) => Err ( err) ,
1780
+ Outcome :: Error ( ( _, err) ) => Err ( err) ,
1781
1781
}
1782
1782
}
1783
1783
@@ -1997,8 +1997,8 @@ impl rocket::route::Handler for CatchAllOptionsRouteHandler {
1997
1997
) -> rocket:: route:: Outcome < ' r > {
1998
1998
let guard: Guard < ' _ > = match request. guard ( ) . await {
1999
1999
Outcome :: Success ( guard) => guard,
2000
- Outcome :: Failure ( ( status, _) ) => return rocket:: route:: Outcome :: failure ( status) ,
2001
- Outcome :: Forward ( ( ) ) => unreachable ! ( "Should not be reachable" ) ,
2000
+ Outcome :: Error ( ( status, _) ) => return rocket:: route:: Outcome :: Error ( status) ,
2001
+ Outcome :: Forward ( _ ) => unreachable ! ( "Should not be reachable" ) ,
2002
2002
} ;
2003
2003
2004
2004
info_ ! (
@@ -2461,7 +2461,7 @@ mod tests {
2461
2461
#[ test]
2462
2462
fn all_allowed_headers_are_validated_correctly ( ) {
2463
2463
let allowed_headers = AllOrSome :: All ;
2464
- let requested_headers = vec ! [ "Bar" , "Foo" ] ;
2464
+ let requested_headers = [ "Bar" , "Foo" ] ;
2465
2465
2466
2466
not_err ! ( validate_allowed_headers(
2467
2467
& FromStr :: from_str( & requested_headers. join( "," ) ) . unwrap( ) ,
@@ -2473,8 +2473,8 @@ mod tests {
2473
2473
/// echoes back the list that is actually requested for and not the whole list
2474
2474
#[ test]
2475
2475
fn allowed_headers_are_validated_correctly ( ) {
2476
- let allowed_headers = vec ! [ "Bar" , "Baz" , "Foo" ] ;
2477
- let requested_headers = vec ! [ "Bar" , "Foo" ] ;
2476
+ let allowed_headers = [ "Bar" , "Baz" , "Foo" ] ;
2477
+ let requested_headers = [ "Bar" , "Foo" ] ;
2478
2478
2479
2479
not_err ! ( validate_allowed_headers(
2480
2480
& FromStr :: from_str( & requested_headers. join( "," ) ) . unwrap( ) ,
@@ -2490,8 +2490,8 @@ mod tests {
2490
2490
#[ test]
2491
2491
#[ should_panic( expected = "HeadersNotAllowed" ) ]
2492
2492
fn allowed_headers_errors_on_non_subset ( ) {
2493
- let allowed_headers = vec ! [ "Bar" , "Baz" , "Foo" ] ;
2494
- let requested_headers = vec ! [ "Bar" , "Foo" , "Unknown" ] ;
2493
+ let allowed_headers = [ "Bar" , "Baz" , "Foo" ] ;
2494
+ let requested_headers = [ "Bar" , "Foo" , "Unknown" ] ;
2495
2495
2496
2496
validate_allowed_headers (
2497
2497
& FromStr :: from_str ( & requested_headers. join ( "," ) ) . unwrap ( ) ,
0 commit comments