mirror of
https://github.com/robertwayne/axum-htmx
synced 2024-11-24 04:12:50 +01:00
Merge pull request #8 from ItsEthra/axum-core
Use axum-core,async-trait,http instead of axum
This commit is contained in:
commit
9ee6bf7fc2
5 changed files with 20 additions and 23 deletions
|
@ -17,7 +17,9 @@ guards = ["tower", "futures-core", "pin-project-lite"]
|
||||||
serde = ["dep:serde", "dep:serde_json"]
|
serde = ["dep:serde", "dep:serde_json"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
axum = { version = "0.7", default-features = false }
|
axum-core = "0.4"
|
||||||
|
http = { version = "1.0.0", default-features = false }
|
||||||
|
async-trait = "0.1.74"
|
||||||
|
|
||||||
# Optional dependencies required for the `guards` feature.
|
# Optional dependencies required for the `guards` feature.
|
||||||
tower = { version = "0.4", default-features = false, optional = true }
|
tower = { version = "0.4", default-features = false, optional = true }
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
//! Axum extractors for htmx request headers.
|
//! Axum extractors for htmx request headers.
|
||||||
|
|
||||||
use axum::{extract::FromRequestParts, http::request::Parts};
|
use async_trait::async_trait;
|
||||||
|
use axum_core::extract::FromRequestParts;
|
||||||
|
use http::request::Parts;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
HX_BOOSTED, HX_CURRENT_URL, HX_HISTORY_RESTORE_REQUEST, HX_PROMPT, HX_REQUEST, HX_TARGET,
|
HX_BOOSTED, HX_CURRENT_URL, HX_HISTORY_RESTORE_REQUEST, HX_PROMPT, HX_REQUEST, HX_TARGET,
|
||||||
|
@ -19,7 +21,7 @@ use crate::{
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct HxBoosted(pub bool);
|
pub struct HxBoosted(pub bool);
|
||||||
|
|
||||||
#[axum::async_trait]
|
#[async_trait]
|
||||||
impl<S> FromRequestParts<S> for HxBoosted
|
impl<S> FromRequestParts<S> for HxBoosted
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
|
@ -45,7 +47,7 @@ where
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HxCurrentUrl(pub Option<String>);
|
pub struct HxCurrentUrl(pub Option<String>);
|
||||||
|
|
||||||
#[axum::async_trait]
|
#[async_trait]
|
||||||
impl<S> FromRequestParts<S> for HxCurrentUrl
|
impl<S> FromRequestParts<S> for HxCurrentUrl
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
|
@ -70,7 +72,7 @@ where
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct HxHistoryRestoreRequest(pub bool);
|
pub struct HxHistoryRestoreRequest(pub bool);
|
||||||
|
|
||||||
#[axum::async_trait]
|
#[async_trait]
|
||||||
impl<S> FromRequestParts<S> for HxHistoryRestoreRequest
|
impl<S> FromRequestParts<S> for HxHistoryRestoreRequest
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
|
@ -96,7 +98,7 @@ where
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HxPrompt(pub Option<String>);
|
pub struct HxPrompt(pub Option<String>);
|
||||||
|
|
||||||
#[axum::async_trait]
|
#[async_trait]
|
||||||
impl<S> FromRequestParts<S> for HxPrompt
|
impl<S> FromRequestParts<S> for HxPrompt
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
|
@ -124,7 +126,7 @@ where
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct HxRequest(pub bool);
|
pub struct HxRequest(pub bool);
|
||||||
|
|
||||||
#[axum::async_trait]
|
#[async_trait]
|
||||||
impl<S> FromRequestParts<S> for HxRequest
|
impl<S> FromRequestParts<S> for HxRequest
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
|
@ -151,7 +153,7 @@ where
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HxTarget(pub Option<String>);
|
pub struct HxTarget(pub Option<String>);
|
||||||
|
|
||||||
#[axum::async_trait]
|
#[async_trait]
|
||||||
impl<S> FromRequestParts<S> for HxTarget
|
impl<S> FromRequestParts<S> for HxTarget
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
|
@ -180,7 +182,7 @@ where
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HxTriggerName(pub Option<String>);
|
pub struct HxTriggerName(pub Option<String>);
|
||||||
|
|
||||||
#[axum::async_trait]
|
#[async_trait]
|
||||||
impl<S> FromRequestParts<S> for HxTriggerName
|
impl<S> FromRequestParts<S> for HxTriggerName
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
|
@ -209,7 +211,7 @@ where
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HxTrigger(pub Option<String>);
|
pub struct HxTrigger(pub Option<String>);
|
||||||
|
|
||||||
#[axum::async_trait]
|
#[async_trait]
|
||||||
impl<S> FromRequestParts<S> for HxTrigger
|
impl<S> FromRequestParts<S> for HxTrigger
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
|
|
|
@ -7,11 +7,8 @@ use std::{
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
use axum::{
|
|
||||||
http::{header::LOCATION, Request, StatusCode},
|
|
||||||
response::Response,
|
|
||||||
};
|
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
|
use http::{header::LOCATION, response::Response, Request, StatusCode};
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
use tower::{Layer, Service};
|
use tower::{Layer, Service};
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,8 @@
|
||||||
|
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
|
||||||
use axum::{
|
use axum_core::response::{IntoResponse, IntoResponseParts, ResponseParts};
|
||||||
http::{header::InvalidHeaderValue, HeaderValue, StatusCode, Uri},
|
use http::{header::InvalidHeaderValue, HeaderValue, StatusCode, Uri};
|
||||||
response::{IntoResponse, IntoResponseParts, ResponseParts},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::headers;
|
use crate::headers;
|
||||||
|
|
||||||
|
@ -392,7 +390,7 @@ impl From<serde_json::Error> for HxError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoResponse for HxError {
|
impl IntoResponse for HxError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum_core::response::Response {
|
||||||
match self {
|
match self {
|
||||||
Self::InvalidHeaderValue(_) => {
|
Self::InvalidHeaderValue(_) => {
|
||||||
(StatusCode::INTERNAL_SERVER_ERROR, "invalid header value").into_response()
|
(StatusCode::INTERNAL_SERVER_ERROR, "invalid header value").into_response()
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use axum::{
|
use axum_core::response::{IntoResponseParts, ResponseParts};
|
||||||
http::{HeaderValue, Uri},
|
use http::{HeaderValue, Uri};
|
||||||
response::{IntoResponseParts, ResponseParts},
|
|
||||||
};
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue