2024-05-19 12:22:56 +02:00
|
|
|
use serde::Serialize;
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
use axum::http::{HeaderMap, Uri};
|
|
|
|
|
|
2024-06-23 20:15:33 +02:00
|
|
|
/// Location must match client side interface
|
|
|
|
|
#[derive(Serialize, Debug)]
|
|
|
|
|
pub struct Location {
|
|
|
|
|
href: String,
|
|
|
|
|
pathname: String,
|
|
|
|
|
search: HashMap<String, String>,
|
|
|
|
|
search_str: String,
|
|
|
|
|
hash: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Location {
|
|
|
|
|
pub fn pathname(&self) -> &String {
|
|
|
|
|
&self.pathname
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> From<&'a Uri> for Location {
|
|
|
|
|
fn from(uri: &Uri) -> Self {
|
|
|
|
|
Location {
|
|
|
|
|
href: uri.to_string(),
|
|
|
|
|
pathname: uri.path().to_string(),
|
|
|
|
|
// TODO: handler search map
|
|
|
|
|
search: HashMap::new(),
|
|
|
|
|
search_str: uri.query().unwrap_or("").to_string(),
|
|
|
|
|
hash: "".to_string(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-02 20:32:53 +02:00
|
|
|
#[derive(Debug, Clone)]
|
2024-05-19 12:22:56 +02:00
|
|
|
pub struct Request<'a> {
|
|
|
|
|
uri: &'a Uri,
|
2024-06-12 13:20:44 +02:00
|
|
|
pub headers: &'a HeaderMap,
|
2024-06-02 20:32:53 +02:00
|
|
|
pub params: HashMap<String, String>,
|
2024-05-19 12:22:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> Request<'a> {
|
2024-06-02 20:32:53 +02:00
|
|
|
pub fn new(
|
|
|
|
|
uri: &'a Uri,
|
|
|
|
|
headers: &'a HeaderMap,
|
|
|
|
|
params: HashMap<String, String>,
|
|
|
|
|
) -> Request<'a> {
|
|
|
|
|
Request {
|
|
|
|
|
uri,
|
|
|
|
|
headers,
|
|
|
|
|
params,
|
|
|
|
|
}
|
2024-05-19 12:22:56 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-23 20:15:33 +02:00
|
|
|
pub fn location(&self) -> Location {
|
|
|
|
|
Location::from(self.uri)
|
2024-05-19 12:22:56 +02:00
|
|
|
}
|
|
|
|
|
}
|