read_url/http/
http_url.rs

1use super::super::{context::*, url::*};
2
3use std::fmt;
4
5//
6// HttpUrl
7//
8
9/// An HTTP URL.
10///
11/// The URL scheme is either "http:" or "https:".
12///
13/// The [URL::base] and [URL::relative] functions interpret the path segment of the URL
14/// as a Unix-style filesystem path, whereby the path separator is "/", and "." and
15/// ".." are supported for path traversal.
16#[derive(Clone, Debug)]
17pub struct HttpUrl {
18    /// The [Url](url::Url).
19    pub url: url::Url,
20
21    pub(crate) context: UrlContextRef,
22}
23
24impl HttpUrl {
25    /// Constructor.
26    pub fn new(context: &UrlContextRef, url: url::Url) -> Self {
27        Self { url, context: context.clone() }
28    }
29
30    /// Constructor.
31    pub fn new_with(&self, path: &str) -> Self {
32        let mut url = self.url.clone();
33        url.set_path(path);
34        url.set_query(None);
35        url.set_fragment(None);
36        Self::new(&self.context, url)
37    }
38}
39
40impl fmt::Display for HttpUrl {
41    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
42        write!(formatter, "{}", self.url)
43    }
44}
45
46// Conversions
47
48impl Into<UrlRef> for HttpUrl {
49    fn into(self) -> UrlRef {
50        Box::new(self)
51    }
52}