Files
tuono/crates/tuono_lib/src/request.rs
T

55 lines
1.1 KiB
Rust
Raw Normal View History

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
}
}
2024-07-09 19:00:48 +02:00
impl From<Uri> for Location {
fn from(uri: Uri) -> Self {
2024-06-23 20:15:33 +02:00
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-07-09 19:00:48 +02:00
pub struct Request {
uri: Uri,
pub headers: HeaderMap,
2024-06-02 20:32:53 +02:00
pub params: HashMap<String, String>,
}
2024-07-09 19:00:48 +02:00
impl Request {
pub fn new(uri: Uri, headers: HeaderMap, params: HashMap<String, String>) -> Request {
2024-06-02 20:32:53 +02:00
Request {
uri,
headers,
params,
}
}
2024-06-23 20:15:33 +02:00
pub fn location(&self) -> Location {
2024-07-09 19:00:48 +02:00
Location::from(self.uri.to_owned())
}
}