Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to axum 0.8 #2705

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 32 additions & 51 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exclude = [
]

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

# axum dependencies
axum = { version = "0.7.3", features = ["macros"] }
axum-extra = { version = "0.9.1", features = ["typed-header"] }
async-trait = "0.1.83"
axum = { version = "0.8.1", features = ["macros"] }
axum-extra = { version = "0.10.0", features = ["typed-header"] }
tower = "0.5.1"
tower-http = { version = "0.6.0", features = ["fs", "trace", "timeout", "catch-panic"] }
mime = "0.3.16"
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/github.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::Result;
use crate::Config;
use axum::async_trait;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use reqwest::{
header::{HeaderMap, HeaderValue, ACCEPT, AUTHORIZATION, USER_AGENT},
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/gitlab.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::Result;
use axum::async_trait;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use reqwest::{
header::{HeaderMap, HeaderValue, ACCEPT, AUTHORIZATION, USER_AGENT},
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::error::Result;
use crate::repositories::{GitHub, GitLab, RateLimitReached};
use crate::utils::MetadataPackage;
use crate::{db::Pool, Config};
use axum::async_trait;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use futures_util::stream::TryStreamExt;
use once_cell::sync::Lazy;
Expand Down
25 changes: 22 additions & 3 deletions src/web/extractors.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::db::{AsyncPoolClient, Pool};
use anyhow::Context as _;
use axum::{
async_trait,
extract::{Extension, FromRequestParts},
extract::{Extension, FromRequestParts, OptionalFromRequestParts},
http::request::Parts,
RequestPartsExt,
};
Expand All @@ -20,7 +19,6 @@ use super::error::AxumNope;
#[derive(Debug)]
pub(crate) struct DbConnection(AsyncPoolClient);

#[async_trait]
impl<S> FromRequestParts<S> for DbConnection
where
S: Send + Sync,
Expand Down Expand Up @@ -55,11 +53,32 @@ impl DerefMut for DbConnection {
/// as error response instead of a plain text "bad request"
#[allow(clippy::disallowed_types)]
mod path_impl {
use serde::de::DeserializeOwned;

use super::*;

#[derive(FromRequestParts)]
#[from_request(via(axum::extract::Path), rejection(AxumNope))]
pub(crate) struct Path<T>(pub T);

impl<T, S> OptionalFromRequestParts<S> for Path<T>
where
T: DeserializeOwned + Send + 'static,
S: Send + Sync,
{
type Rejection = AxumNope;

async fn from_request_parts(
parts: &mut Parts,
_state: &S,
) -> Result<Option<Self>, Self::Rejection> {
parts
.extract::<Option<axum::extract::Path<T>>>()
.await
.map(|path| path.map(|obj| Path(obj.0)))
.map_err(|err| AxumNope::BadRequest(err.into()))
}
}
}

pub(crate) use path_impl::Path;
Expand Down
17 changes: 10 additions & 7 deletions src/web/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ mod tests {
fn test_response_times_count_being_collected() {
const ROUTES: &[(&str, &str)] = &[
("/", "/"),
("/crate/hexponent/0.2.0", "/crate/:name/:version"),
("/crate/rcc/0.0.0", "/crate/:name/:version"),
("/crate/hexponent/0.2.0", "/crate/{name}/{version}"),
("/crate/rcc/0.0.0", "/crate/{name}/{version}"),
(
"/crate/rcc/0.0.0/builds.json",
"/crate/:name/:version/builds.json",
"/crate/{name}/{version}/builds.json",
),
(
"/crate/rcc/0.0.0/status.json",
"/crate/:name/:version/status.json",
"/crate/{name}/{version}/status.json",
),
("/-/static/index.js", "static resource"),
("/-/static/menu.js", "static resource"),
Expand All @@ -139,12 +139,15 @@ mod tests {
("/releases/recent-failures", "/releases/recent-failures"),
(
"/releases/recent-failures/1",
"/releases/recent-failures/:page",
"/releases/recent-failures/{page}",
),
("/releases/recent/1", "/releases/recent/:page"),
("/releases/recent/1", "/releases/recent/{page}"),
("/-/static/robots.txt", "static resource"),
("/sitemap.xml", "/sitemap.xml"),
("/-/sitemap/a/sitemap.xml", "/-/sitemap/:letter/sitemap.xml"),
(
"/-/sitemap/a/sitemap.xml",
"/-/sitemap/{letter}/sitemap.xml",
),
("/-/static/style.css", "static resource"),
("/-/static/vendored.css", "static resource"),
("/rustdoc/rcc/0.0.0/rcc/index.html", "rustdoc page"),
Expand Down
Loading
Loading