Skip to content

Commit c1be79c

Browse files
sypharGuillaumeGomez
authored andcommitted
upgrade axum to 0.8
1 parent 144032c commit c1be79c

File tree

9 files changed

+120
-115
lines changed

9 files changed

+120
-115
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exclude = [
1717
]
1818

1919
[dependencies]
20-
sentry = { version = "0.35.0", features = ["panic", "tracing", "tower-http", "anyhow", "backtrace"] }
20+
sentry = { version = "0.36.0", features = ["panic", "tracing", "tower-http", "anyhow", "backtrace"] }
2121
log = "0.4"
2222
tracing = "0.1.37"
2323
tracing-subscriber = { version = "0.3.16", default-features = false, features = ["ansi", "fmt", "json", "env-filter", "tracing-log"] }
@@ -78,8 +78,9 @@ serde_json = "1.0"
7878
serde_with = "3.4.0"
7979

8080
# axum dependencies
81-
axum = { version = "0.7.3", features = ["macros"] }
82-
axum-extra = { version = "0.9.1", features = ["typed-header"] }
81+
async-trait = "0.1.83"
82+
axum = { version = "0.8.1", features = ["macros"] }
83+
axum-extra = { version = "0.10.0", features = ["typed-header"] }
8384
tower = "0.5.1"
8485
tower-http = { version = "0.6.0", features = ["fs", "trace", "timeout", "catch-panic"] }
8586
mime = "0.3.16"

src/repositories/github.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::error::Result;
22
use crate::Config;
3-
use axum::async_trait;
3+
use async_trait::async_trait;
44
use chrono::{DateTime, Utc};
55
use reqwest::{
66
header::{HeaderMap, HeaderValue, ACCEPT, AUTHORIZATION, USER_AGENT},

src/repositories/gitlab.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::error::Result;
2-
use axum::async_trait;
2+
use async_trait::async_trait;
33
use chrono::{DateTime, Utc};
44
use reqwest::{
55
header::{HeaderMap, HeaderValue, ACCEPT, AUTHORIZATION, USER_AGENT},

src/repositories/updater.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::error::Result;
22
use crate::repositories::{GitHub, GitLab, RateLimitReached};
33
use crate::utils::MetadataPackage;
44
use crate::{db::Pool, Config};
5-
use axum::async_trait;
5+
use async_trait::async_trait;
66
use chrono::{DateTime, Utc};
77
use futures_util::stream::TryStreamExt;
88
use once_cell::sync::Lazy;

src/web/extractors.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::db::{AsyncPoolClient, Pool};
22
use anyhow::Context as _;
33
use axum::{
4-
async_trait,
5-
extract::{Extension, FromRequestParts},
4+
extract::{Extension, FromRequestParts, OptionalFromRequestParts},
65
http::request::Parts,
76
RequestPartsExt,
87
};
@@ -20,7 +19,6 @@ use super::error::AxumNope;
2019
#[derive(Debug)]
2120
pub(crate) struct DbConnection(AsyncPoolClient);
2221

23-
#[async_trait]
2422
impl<S> FromRequestParts<S> for DbConnection
2523
where
2624
S: Send + Sync,
@@ -55,11 +53,32 @@ impl DerefMut for DbConnection {
5553
/// as error response instead of a plain text "bad request"
5654
#[allow(clippy::disallowed_types)]
5755
mod path_impl {
56+
use serde::de::DeserializeOwned;
57+
5858
use super::*;
5959

6060
#[derive(FromRequestParts)]
6161
#[from_request(via(axum::extract::Path), rejection(AxumNope))]
6262
pub(crate) struct Path<T>(pub T);
63+
64+
impl<T, S> OptionalFromRequestParts<S> for Path<T>
65+
where
66+
T: DeserializeOwned + Send + 'static,
67+
S: Send + Sync,
68+
{
69+
type Rejection = AxumNope;
70+
71+
async fn from_request_parts(
72+
parts: &mut Parts,
73+
_state: &S,
74+
) -> Result<Option<Self>, Self::Rejection> {
75+
parts
76+
.extract::<Option<axum::extract::Path<T>>>()
77+
.await
78+
.map(|path| path.map(|obj| Path(obj.0)))
79+
.map_err(|err| AxumNope::BadRequest(err.into()))
80+
}
81+
}
6382
}
6483

6584
pub(crate) use path_impl::Path;

src/web/metrics.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ mod tests {
118118
fn test_response_times_count_being_collected() {
119119
const ROUTES: &[(&str, &str)] = &[
120120
("/", "/"),
121-
("/crate/hexponent/0.2.0", "/crate/:name/:version"),
122-
("/crate/rcc/0.0.0", "/crate/:name/:version"),
121+
("/crate/hexponent/0.2.0", "/crate/{name}/{version}"),
122+
("/crate/rcc/0.0.0", "/crate/{name}/{version}"),
123123
(
124124
"/crate/rcc/0.0.0/builds.json",
125-
"/crate/:name/:version/builds.json",
125+
"/crate/{name}/{version}/builds.json",
126126
),
127127
(
128128
"/crate/rcc/0.0.0/status.json",
129-
"/crate/:name/:version/status.json",
129+
"/crate/{name}/{version}/status.json",
130130
),
131131
("/-/static/index.js", "static resource"),
132132
("/-/static/menu.js", "static resource"),
@@ -139,12 +139,15 @@ mod tests {
139139
("/releases/recent-failures", "/releases/recent-failures"),
140140
(
141141
"/releases/recent-failures/1",
142-
"/releases/recent-failures/:page",
142+
"/releases/recent-failures/{page}",
143143
),
144-
("/releases/recent/1", "/releases/recent/:page"),
144+
("/releases/recent/1", "/releases/recent/{page}"),
145145
("/-/static/robots.txt", "static resource"),
146146
("/sitemap.xml", "/sitemap.xml"),
147-
("/-/sitemap/a/sitemap.xml", "/-/sitemap/:letter/sitemap.xml"),
147+
(
148+
"/-/sitemap/a/sitemap.xml",
149+
"/-/sitemap/{letter}/sitemap.xml",
150+
),
148151
("/-/static/style.css", "static resource"),
149152
("/-/static/vendored.css", "static resource"),
150153
("/rustdoc/rcc/0.0.0/rcc/index.html", "rustdoc page"),

0 commit comments

Comments
 (0)