-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create utils module with function for htmx redirects
- Loading branch information
1 parent
e8afc6c
commit 9bdc9fc
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use axum::{ | ||
http::{ | ||
HeaderMap, | ||
}, | ||
}; | ||
|
||
use axum_core::response::IntoResponse; | ||
|
||
use crate::AppError; | ||
|
||
pub fn make_htmx_redirect(request_headers: HeaderMap, target: &str) -> Result<impl IntoResponse, AppError> { | ||
let mut headers = HeaderMap::new(); | ||
let header_name: &str = request_headers | ||
.get("HX-Request") | ||
.filter(|v| *v == "true") | ||
.map_or_else(|| "Location", |_| "HX-Location"); | ||
headers.insert(header_name, target.parse().unwrap()); | ||
Ok(headers) | ||
} |