hyperlocal_with_windows/
uri.rs1use hyper::Uri as HyperUri;
2use std::path::Path;
3
4#[derive(Debug, Clone)]
16pub struct Uri {
17 hyper_uri: HyperUri,
18}
19
20impl Uri {
21 pub fn new(
26 socket: impl AsRef<Path>,
27 path: &str,
28 ) -> Self {
29 let host = hex::encode(socket.as_ref().to_string_lossy().as_bytes());
30 let host_str = format!("unix://{host}:0{path}");
31 let hyper_uri: HyperUri = host_str.parse().unwrap();
32
33 Self { hyper_uri }
34 }
35}
36
37impl From<Uri> for HyperUri {
38 fn from(uri: Uri) -> Self {
39 uri.hyper_uri
40 }
41}
42
43#[cfg(test)]
44mod tests {
45 use super::Uri;
46 use hyper::Uri as HyperUri;
47
48 #[test]
49 fn test_unix_uri_into_hyper_uri() {
50 let unix: HyperUri = Uri::new("foo.sock", "/").into();
51 let expected: HyperUri = "unix://666f6f2e736f636b:0/".parse().unwrap();
52 assert_eq!(unix, expected);
53 }
54}