Skip to content

Support axum 8.0 #25

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

Merged
merged 4 commits into from
Jan 21, 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
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ serde = ["dep:serde", "dep:serde_json"]
auto-vary = ["futures", "tokio", "tower"]

[dependencies]
axum-core = "0.4"
axum-core = "0.5"
http = { version = "1", default-features = false }
async-trait = "0.1"

# Optional dependencies required for the `guards` feature.
tower = { version = "0.5", default-features = false, optional = true }
Expand All @@ -36,8 +35,8 @@ tokio = { version = "1", features = ["sync"], optional = true }
futures = { version = "0.3", default-features = false, optional = true }

[dev-dependencies]
axum = { version = "0.7", default-features = false }
axum-test = "16"
axum = { version = "0.8", default-features = false}
axum-test = "17"
tokio = { version = "1", features = ["full"] }
tokio-test = "0.4"

Expand Down
2 changes: 1 addition & 1 deletion src/auto_vary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(crate) trait Notifier {
fn sender(&mut self) -> Option<Sender<()>>;

fn notify(&mut self) {
if let Some(sender) = self.sender().take() {
if let Some(sender) = self.sender() {
sender.send(()).ok();
}
}
Expand Down
31 changes: 11 additions & 20 deletions src/extractors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Axum extractors for htmx request headers.

use async_trait::async_trait;
use axum_core::extract::FromRequestParts;
use http::request::Parts;

Expand All @@ -21,7 +20,6 @@ use crate::{
#[derive(Debug, Clone, Copy)]
pub struct HxBoosted(pub bool);

#[async_trait]
impl<S> FromRequestParts<S> for HxBoosted
where
S: Send + Sync,
Expand All @@ -30,9 +28,9 @@ where

async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
if parts.headers.contains_key(HX_BOOSTED) {
return Ok(HxBoosted(true));
Ok(HxBoosted(true))
} else {
return Ok(HxBoosted(false));
Ok(HxBoosted(false))
}
}
}
Expand All @@ -47,7 +45,6 @@ where
#[derive(Debug, Clone)]
pub struct HxCurrentUrl(pub Option<http::Uri>);

#[async_trait]
impl<S> FromRequestParts<S> for HxCurrentUrl
where
S: Send + Sync,
Expand All @@ -64,7 +61,7 @@ where
return Ok(HxCurrentUrl(url));
}

return Ok(HxCurrentUrl(None));
Ok(HxCurrentUrl(None))
}
}

Expand All @@ -75,7 +72,6 @@ where
#[derive(Debug, Clone, Copy)]
pub struct HxHistoryRestoreRequest(pub bool);

#[async_trait]
impl<S> FromRequestParts<S> for HxHistoryRestoreRequest
where
S: Send + Sync,
Expand All @@ -84,9 +80,9 @@ where

async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
if parts.headers.contains_key(HX_HISTORY_RESTORE_REQUEST) {
return Ok(HxHistoryRestoreRequest(true));
Ok(HxHistoryRestoreRequest(true))
} else {
return Ok(HxHistoryRestoreRequest(false));
Ok(HxHistoryRestoreRequest(false))
}
}
}
Expand All @@ -101,7 +97,6 @@ where
#[derive(Debug, Clone)]
pub struct HxPrompt(pub Option<String>);

#[async_trait]
impl<S> FromRequestParts<S> for HxPrompt
where
S: Send + Sync,
Expand All @@ -115,7 +110,7 @@ where
}
}

return Ok(HxPrompt(None));
Ok(HxPrompt(None))
}
}

Expand All @@ -129,7 +124,6 @@ where
#[derive(Debug, Clone, Copy)]
pub struct HxRequest(pub bool);

#[async_trait]
impl<S> FromRequestParts<S> for HxRequest
where
S: Send + Sync,
Expand All @@ -144,9 +138,9 @@ where
.map(crate::auto_vary::Notifier::notify);

if parts.headers.contains_key(HX_REQUEST) {
return Ok(HxRequest(true));
Ok(HxRequest(true))
} else {
return Ok(HxRequest(false));
Ok(HxRequest(false))
}
}
}
Expand All @@ -162,7 +156,6 @@ where
#[derive(Debug, Clone)]
pub struct HxTarget(pub Option<String>);

#[async_trait]
impl<S> FromRequestParts<S> for HxTarget
where
S: Send + Sync,
Expand All @@ -182,7 +175,7 @@ where
}
}

return Ok(HxTarget(None));
Ok(HxTarget(None))
}
}

Expand All @@ -197,7 +190,6 @@ where
#[derive(Debug, Clone)]
pub struct HxTriggerName(pub Option<String>);

#[async_trait]
impl<S> FromRequestParts<S> for HxTriggerName
where
S: Send + Sync,
Expand All @@ -217,7 +209,7 @@ where
}
}

return Ok(HxTriggerName(None));
Ok(HxTriggerName(None))
}
}

Expand All @@ -232,7 +224,6 @@ where
#[derive(Debug, Clone)]
pub struct HxTrigger(pub Option<String>);

#[async_trait]
impl<S> FromRequestParts<S> for HxTrigger
where
S: Send + Sync,
Expand All @@ -252,6 +243,6 @@ where
}
}

return Ok(HxTrigger(None));
Ok(HxTrigger(None))
}
}
Loading