Skip to content

Commit ca97afc

Browse files
committed
Upgrade to axum 0.6
1 parent c693162 commit ca97afc

File tree

3 files changed

+34
-38
lines changed

3 files changed

+34
-38
lines changed

ui/Cargo.lock

Lines changed: 16 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fork-bomb-prevention = []
1010

1111
[dependencies]
1212
async-trait = "0.1.52"
13-
axum = { version = "0.5", features = ["headers", "ws"] }
13+
axum = { version = "0.6", features = ["headers", "ws"] }
1414
dotenv = "0.15.0"
1515
env_logger = "0.10.0"
1616
futures = "0.3.21"

ui/src/server_axum.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ use axum::{
2222
},
2323
handler::Handler,
2424
headers::{authorization::Bearer, Authorization, CacheControl, ETag, IfNoneMatch},
25-
http::{header, uri::PathAndQuery, HeaderValue, Method, Request, StatusCode, Uri},
25+
http::{
26+
header, request::Parts, uri::PathAndQuery, HeaderValue, Method, Request, StatusCode, Uri,
27+
},
2628
middleware,
2729
response::IntoResponse,
2830
routing::{get, get_service, post, MethodRouter},
@@ -62,8 +64,8 @@ pub(crate) async fn serve(config: Config) {
6264
let rewrite_help_as_index = middleware::from_fn(rewrite_help_as_index);
6365

6466
let mut app = Router::new()
65-
.fallback(root_files)
66-
.nest("/assets", asset_files)
67+
.fallback_service(root_files)
68+
.nest_service("/assets", asset_files)
6769
.layer(rewrite_help_as_index)
6870
.route("/evaluate.json", post(evaluate))
6971
.route("/compile", post(compile))
@@ -80,6 +82,7 @@ pub(crate) async fn serve(config: Config) {
8082
.route("/meta/version/clippy", get_or_post(meta_version_clippy))
8183
.route("/meta/version/miri", get_or_post(meta_version_miri))
8284
.route("/meta/gist", post(meta_gist_create))
85+
.route("/meta/gist/", post(meta_gist_create)) // compatibility with lax frontend code
8386
.route("/meta/gist/:id", get(meta_gist_get))
8487
.route("/metrics", get(metrics))
8588
.route("/websocket", get(websocket))
@@ -111,7 +114,7 @@ pub(crate) async fn serve(config: Config) {
111114
.unwrap();
112115
}
113116

114-
fn get_or_post<T: 'static>(handler: impl Handler<T> + Copy) -> MethodRouter {
117+
fn get_or_post<T: 'static>(handler: impl Handler<T, ()> + Copy) -> MethodRouter {
115118
get(handler).post(handler)
116119
}
117120

@@ -419,16 +422,16 @@ impl MetricsAuthorization {
419422
}
420423

421424
#[async_trait]
422-
impl<B> extract::FromRequest<B> for MetricsAuthorization
425+
impl<S> extract::FromRequestParts<S> for MetricsAuthorization
423426
where
424-
B: Send,
427+
S: Send + Sync,
425428
{
426429
type Rejection = MetricsAuthorizationRejection;
427430

428-
async fn from_request(req: &mut extract::RequestParts<B>) -> Result<Self, Self::Rejection> {
429-
match Extension::<MetricsToken>::from_request(req).await {
431+
async fn from_request_parts(req: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
432+
match Extension::<MetricsToken>::from_request_parts(req, state).await {
430433
Ok(Extension(expected)) => {
431-
match TypedHeader::<Authorization<Bearer>>::from_request(req).await {
434+
match TypedHeader::<Authorization<Bearer>>::from_request_parts(req, state).await {
432435
Ok(TypedHeader(Authorization(actual))) => {
433436
if actual.token() == *expected.0 {
434437
Ok(Self)
@@ -635,17 +638,18 @@ impl IntoResponse for Error {
635638
struct Json<T>(T);
636639

637640
#[async_trait]
638-
impl<T, B> extract::FromRequest<B> for Json<T>
641+
impl<T, S, B> extract::FromRequest<S, B> for Json<T>
639642
where
640643
T: serde::de::DeserializeOwned,
641-
B: axum::body::HttpBody + Send,
644+
S: Send + Sync,
645+
B: axum::body::HttpBody + Send + 'static,
642646
B::Data: Send,
643647
B::Error: Into<axum::BoxError>,
644648
{
645649
type Rejection = axum::response::Response;
646650

647-
async fn from_request(req: &mut extract::RequestParts<B>) -> Result<Self, Self::Rejection> {
648-
match axum::Json::<T>::from_request(req).await {
651+
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
652+
match axum::Json::<T>::from_request(req, state).await {
649653
Ok(v) => Ok(Self(v.0)),
650654
Err(e) => {
651655
let error = format!("Unable to deserialize request: {e}");

0 commit comments

Comments
 (0)