diff --git a/src/http_interop.rs b/src/http_interop.rs index 0c0e161..f287612 100644 --- a/src/http_interop.rs +++ b/src/http_interop.rs @@ -128,6 +128,30 @@ impl From for http::Response { } } +/// Converts a [Response](crate::Response) into an [http::Response], where the +/// body is a Vec. +/// +/// Due to slight differences in how headers are handled, this means if a header +/// from a [Response](crate::Response) is not valid UTF-8, it will not be +/// included in the resulting [http::Response]. +/// +/// Requires feature `ureq = { version = "*", features = ["http"] }` +/// ``` +/// # fn main() -> Result<(), ureq::Error> { +/// # ureq::is_test(true); +/// let response = ureq::get("http://example.com").call()?; +/// let http_response: http::Response> = response.into(); +/// # Ok(()) +/// # } +/// ``` +impl From for http::Response> { + fn from(value: Response) -> Self { + create_builder(&value) + .body(value.into_string().unwrap().into_bytes()) + .unwrap() + } +} + /// Converts an [http] [Builder](http::request::Builder) into a [Request](crate::Request) /// /// This will safely handle cases where a builder is not fully "complete" to