mirror of
https://github.com/robertwayne/axum-htmx
synced 2024-12-25 17:59: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
|
||||
/// just contains the current url.
|
||||
///
|
||||
/// This extractor will always return a value. If the header is not present, it
|
||||
/// will return `None`.
|
||||
/// This extractor will always return a value. If the header is not present, or extractor fails to parse the url
|
||||
/// it will return `None`.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct HxCurrentUrl(pub Option<String>);
|
||||
pub struct HxCurrentUrl(pub Option<http::Uri>);
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for HxCurrentUrl
|
||||
|
@ -56,9 +56,11 @@ where
|
|||
|
||||
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 Ok(url) = url.to_str() {
|
||||
return Ok(HxCurrentUrl(Some(url.to_string())));
|
||||
}
|
||||
let url = url
|
||||
.to_str()
|
||||
.ok()
|
||||
.and_then(|url| url.parse::<http::Uri>().ok());
|
||||
return Ok(HxCurrentUrl(url));
|
||||
}
|
||||
|
||||
return Ok(HxCurrentUrl(None));
|
||||
|
|
Loading…
Reference in a new issue