mirror of
https://github.com/robertwayne/axum-htmx
synced 2024-12-27 02:39:32 +01:00
Use http::Uri in HxCurrentUrl
This commit is contained in:
parent
a04e131a69
commit
140a74c071
1 changed files with 8 additions and 6 deletions
|
@ -42,10 +42,10 @@ where
|
||||||
/// This is set on every request made by htmx itself. As its name implies, it
|
/// This is set on every request made by htmx itself. As its name implies, it
|
||||||
/// just contains the current url.
|
/// just contains the current url.
|
||||||
///
|
///
|
||||||
/// This extractor will always return a value. If the header is not present, it
|
/// This extractor will always return a value. If the header is not present, or extractor fails to parse the url
|
||||||
/// will return `None`.
|
/// it will return `None`.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HxCurrentUrl(pub Option<String>);
|
pub struct HxCurrentUrl(pub Option<http::Uri>);
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<S> FromRequestParts<S> for HxCurrentUrl
|
impl<S> FromRequestParts<S> for HxCurrentUrl
|
||||||
|
@ -56,9 +56,11 @@ where
|
||||||
|
|
||||||
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
|
||||||
if let Some(url) = parts.headers.get(HX_CURRENT_URL) {
|
if let Some(url) = parts.headers.get(HX_CURRENT_URL) {
|
||||||
if let Ok(url) = url.to_str() {
|
let url = url
|
||||||
return Ok(HxCurrentUrl(Some(url.to_string())));
|
.to_str()
|
||||||
}
|
.ok()
|
||||||
|
.and_then(|url| url.parse::<http::Uri>().ok());
|
||||||
|
return Ok(HxCurrentUrl(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(HxCurrentUrl(None));
|
return Ok(HxCurrentUrl(None));
|
||||||
|
|
Loading…
Reference in a new issue