use url::Url;
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct ResponseUrl(pub Url);
pub trait ResponseBuilderExt {
fn url(self, url: Url) -> Self;
}
impl ResponseBuilderExt for http::response::Builder {
fn url(self, url: Url) -> Self {
self.extension(ResponseUrl(url))
}
}
#[cfg(test)]
mod tests {
use super::{ResponseBuilderExt, ResponseUrl};
use http::response::Builder;
use url::Url;
#[test]
fn test_response_builder_ext() {
let url = Url::parse("http://example.com").unwrap();
let response = Builder::new()
.status(200)
.url(url.clone())
.body(())
.unwrap();
assert_eq!(
response.extensions().get::<ResponseUrl>(),
Some(&ResponseUrl(url))
);
}
}