2024-08-20 06:05:01 +00:00
|
|
|
use tiny_http::Request;
|
|
|
|
|
|
|
|
pub trait Url {
|
2024-08-20 13:24:32 +00:00
|
|
|
fn get_url_without_parameters(&self) -> String;
|
2024-08-20 06:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Url for Request {
|
|
|
|
fn get_url_without_parameters(&self) -> String {
|
|
|
|
self.url().split("?").next().unwrap().to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-20 13:24:32 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use crate::entities::request::*;
|
|
|
|
use tiny_http::{Request, TestRequest};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_get_url_without_parameters() {
|
|
|
|
let request = Request::from(TestRequest::new().with_path("/test?key=value"));
|
|
|
|
|
|
|
|
let actual = request.get_url_without_parameters();
|
|
|
|
|
|
|
|
assert_eq!(actual, "/test");
|
|
|
|
|
|
|
|
let request2 = Request::from(TestRequest::new().with_path("/test2"));
|
|
|
|
|
|
|
|
assert_eq!(request2.get_url_without_parameters(), "/test2");
|
|
|
|
}
|
|
|
|
}
|