Files
tuono/crates/tuono_lib/src/request.rs
T
Valerio Ageno 9c707466db Optimize build assets (#6)
* feat: handle Dev and Prod modes

* fix: remove useles variable override

* refactor: ssr entry point fn

* feat: pass Mode from server to client

* feat: enable read file from out/client dir

* feat: load manifest data from server side

* feat: remap manifest when loaded

* feat: load correct bundle server side

* doc: update README.md

* doc: update tutorial
2024-06-23 20:15:33 +02:00

59 lines
1.2 KiB
Rust

use serde::Serialize;
use std::collections::HashMap;
use axum::http::{HeaderMap, Uri};
/// 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(),
}
}
}
#[derive(Debug, Clone)]
pub struct Request<'a> {
uri: &'a Uri,
pub headers: &'a HeaderMap,
pub params: HashMap<String, String>,
}
impl<'a> Request<'a> {
pub fn new(
uri: &'a Uri,
headers: &'a HeaderMap,
params: HashMap<String, String>,
) -> Request<'a> {
Request {
uri,
headers,
params,
}
}
pub fn location(&self) -> Location {
Location::from(self.uri)
}
}