2024-05-19 12:22:56 +02:00
|
|
|
use serde::Serialize;
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
use axum::http::{HeaderMap, Uri};
|
|
|
|
|
|
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,
|
|
|
|
|
headers: &'a HeaderMap,
|
2024-06-02 20:32:53 +02:00
|
|
|
pub params: HashMap<String, String>,
|
2024-05-19 12:22:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Location must match client side interface
|
|
|
|
|
#[derive(Serialize, Debug)]
|
|
|
|
|
pub struct Location<'a> {
|
|
|
|
|
href: String,
|
|
|
|
|
pathname: &'a str,
|
|
|
|
|
search: HashMap<String, String>,
|
|
|
|
|
search_str: &'a str,
|
|
|
|
|
/// Server does not need it. Will be hanlder client side
|
|
|
|
|
hash: &'a str,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn location(&self) -> Location<'a> {
|
|
|
|
|
Location {
|
|
|
|
|
href: self.uri.to_string(),
|
|
|
|
|
pathname: &self.uri.path(),
|
|
|
|
|
// TODO: hanler search map
|
|
|
|
|
search: HashMap::new(),
|
|
|
|
|
search_str: &self.uri.query().unwrap_or(""),
|
|
|
|
|
hash: "",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|