Skip to content

Commit 6b5205c

Browse files
j03-devlawliet89
andauthored
Update to latest master Rocket version (#89) (#114)
* Update to latest master Rocket version (#89) * Fix "useless `vec!`" * Fix docs --------- Co-authored-by: Yong Wen Chua <[email protected]>
1 parent 985098d commit 6b5205c

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ serialization = ["serde", "serde_derive", "unicase_serde"]
2222

2323
[dependencies]
2424
regex = "1.7.2"
25-
rocket = { version = "0.5.0-rc.3", default-features = false }
25+
rocket = { version = "0.5.0-rc.4", default-features = false }
2626
log = "0.4"
2727
unicase = "2.6"
2828
url = "2.3.1"

src/fairing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl rocket::route::Handler for FairingErrorRoute {
3434
500
3535
});
3636
let status = Status::from_code(status).unwrap_or(Status::InternalServerError);
37-
Outcome::Failure(status)
37+
Outcome::Error(status)
3838
}
3939
}
4040

src/headers.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ impl Origin {
101101
match request.headers().get_one("Origin") {
102102
Some(origin) => match Self::from_str(origin) {
103103
Ok(origin) => Outcome::Success(origin),
104-
Err(e) => Outcome::Failure((Status::BadRequest, e)),
104+
Err(e) => Outcome::Error((Status::BadRequest, e)),
105105
},
106-
None => Outcome::Forward(()),
106+
None => Outcome::Forward(Status::default()),
107107
}
108108
}
109109
}
@@ -164,9 +164,9 @@ impl AccessControlRequestMethod {
164164
match request.headers().get_one("Access-Control-Request-Method") {
165165
Some(request_method) => match Self::from_str(request_method) {
166166
Ok(request_method) => Outcome::Success(request_method),
167-
Err(_) => Outcome::Failure((Status::BadRequest, crate::Error::BadRequestMethod)),
167+
Err(_) => Outcome::Error((Status::BadRequest, crate::Error::BadRequestMethod)),
168168
},
169-
None => Outcome::Forward(()),
169+
None => Outcome::Forward(Status::default()),
170170
}
171171
}
172172
}
@@ -214,7 +214,7 @@ impl AccessControlRequestHeaders {
214214
unreachable!("`AccessControlRequestHeaders::from_str` should never fail")
215215
}
216216
},
217-
None => Outcome::Forward(()),
217+
None => Outcome::Forward(Status::default()),
218218
}
219219
}
220220
}

src/lib.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ Rocket's [managed state](https://rocket.rs/guide/state/#managed-state).
134134
verb.
135135
- Then in all the routes you want to enforce CORS on, add a
136136
[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
138138
`Option` or `Result` because the guard will let non-CORS requests through and will take over
139139
error handling in case of errors.
140140
- 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`.
142142
143143
Refer to the [example](https://github.com/lawliet89/rocket_cors/blob/master/examples/guard.rs).
144144
@@ -1515,13 +1515,13 @@ impl<'r> FromRequest<'r> for Guard<'r> {
15151515
Outcome::Success(options) => options,
15161516
_ => {
15171517
let error = Error::MissingCorsInRocketState;
1518-
return Outcome::Failure((error.status(), error));
1518+
return Outcome::Error((error.status(), error));
15191519
}
15201520
};
15211521

15221522
match Response::validate_and_build(options, request) {
15231523
Ok(response) => Outcome::Success(Self::new(response)),
1524-
Err(error) => Outcome::Failure((error.status(), error)),
1524+
Err(error) => Outcome::Error((error.status(), error)),
15251525
}
15261526
}
15271527
}
@@ -1757,27 +1757,27 @@ fn validate_allowed_headers(
17571757
/// Gets the `Origin` request header from the request
17581758
fn origin(request: &Request<'_>) -> Result<Option<Origin>, Error> {
17591759
match Origin::from_request_sync(request) {
1760-
Outcome::Forward(()) => Ok(None),
1760+
Outcome::Forward(_) => Ok(None),
17611761
Outcome::Success(origin) => Ok(Some(origin)),
1762-
Outcome::Failure((_, err)) => Err(err),
1762+
Outcome::Error((_, err)) => Err(err),
17631763
}
17641764
}
17651765

17661766
/// Gets the `Access-Control-Request-Method` request header from the request
17671767
fn request_method(request: &Request<'_>) -> Result<Option<AccessControlRequestMethod>, Error> {
17681768
match AccessControlRequestMethod::from_request_sync(request) {
1769-
Outcome::Forward(()) => Ok(None),
1769+
Outcome::Forward(_) => Ok(None),
17701770
Outcome::Success(method) => Ok(Some(method)),
1771-
Outcome::Failure((_, err)) => Err(err),
1771+
Outcome::Error((_, err)) => Err(err),
17721772
}
17731773
}
17741774

17751775
/// Gets the `Access-Control-Request-Headers` request header from the request
17761776
fn request_headers(request: &Request<'_>) -> Result<Option<AccessControlRequestHeaders>, Error> {
17771777
match AccessControlRequestHeaders::from_request_sync(request) {
1778-
Outcome::Forward(()) => Ok(None),
1778+
Outcome::Forward(_) => Ok(None),
17791779
Outcome::Success(geaders) => Ok(Some(geaders)),
1780-
Outcome::Failure((_, err)) => Err(err),
1780+
Outcome::Error((_, err)) => Err(err),
17811781
}
17821782
}
17831783

@@ -1997,8 +1997,8 @@ impl rocket::route::Handler for CatchAllOptionsRouteHandler {
19971997
) -> rocket::route::Outcome<'r> {
19981998
let guard: Guard<'_> = match request.guard().await {
19991999
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"),
20022002
};
20032003

20042004
info_!(
@@ -2461,7 +2461,7 @@ mod tests {
24612461
#[test]
24622462
fn all_allowed_headers_are_validated_correctly() {
24632463
let allowed_headers = AllOrSome::All;
2464-
let requested_headers = vec!["Bar", "Foo"];
2464+
let requested_headers = ["Bar", "Foo"];
24652465

24662466
not_err!(validate_allowed_headers(
24672467
&FromStr::from_str(&requested_headers.join(",")).unwrap(),
@@ -2473,8 +2473,8 @@ mod tests {
24732473
/// echoes back the list that is actually requested for and not the whole list
24742474
#[test]
24752475
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"];
24782478

24792479
not_err!(validate_allowed_headers(
24802480
&FromStr::from_str(&requested_headers.join(",")).unwrap(),
@@ -2490,8 +2490,8 @@ mod tests {
24902490
#[test]
24912491
#[should_panic(expected = "HeadersNotAllowed")]
24922492
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"];
24952495

24962496
validate_allowed_headers(
24972497
&FromStr::from_str(&requested_headers.join(",")).unwrap(),

0 commit comments

Comments
 (0)