forked from seanmonstar/reqwest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ResponseBuilderExt not target-dependent
- Loading branch information
1 parent
3879694
commit 1be9c34
Showing
4 changed files
with
50 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use url::Url; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub(crate) struct ResponseUrl(pub Url); | ||
|
||
/// Extension trait for http::response::Builder objects | ||
/// | ||
/// Allows the user to add a `Url` to the http::Response | ||
pub trait ResponseBuilderExt { | ||
/// A builder method for the `http::response::Builder` type that allows the user to add a `Url` | ||
/// to the `http::Response` | ||
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)) | ||
); | ||
} | ||
} |