1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use url::Url;
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct HttpExtUrl(pub Url);
pub trait HttpResponseBuilderExt {
fn url(self, url: Url) -> Self;
}
impl HttpResponseBuilderExt for http::response::Builder {
fn url(self, url: Url) -> Self {
self.extension(HttpExtUrl(url))
}
}
pub trait HttpResponseExt {
fn url(&self) -> Option<Url>;
}
impl<T> HttpResponseExt for http::Response<T> {
fn url(&self) -> Option<Url> {
self.extensions()
.get::<HttpExtUrl>()
.map(|url| url.clone().0)
}
}