@@ -16,6 +16,7 @@ use crate::cookie;
1616use crate :: {
1717 Error , Upgraded ,
1818 core:: { client:: connect:: HttpInfo , ext:: ReasonPhrase } ,
19+ response:: ResponseUrl ,
1920} ;
2021
2122/// A Response to a submitted `Request`.
@@ -442,8 +443,6 @@ impl fmt::Debug for Response {
442443// to use `http::Response`, not `wreq::Response`.
443444impl < T : Into < Body > > From < http:: Response < T > > for Response {
444445 fn from ( r : http:: Response < T > ) -> Response {
445- use crate :: response:: ResponseUrl ;
446-
447446 let ( mut parts, body) = r. into_parts ( ) ;
448447 let body: super :: body:: Body = body. into ( ) ;
449448 let url = parts
@@ -465,7 +464,9 @@ impl From<Response> for http::Response<Body> {
465464 fn from ( r : Response ) -> http:: Response < Body > {
466465 let ( parts, body) = r. res . into_parts ( ) ;
467466 let body = Body :: wrap ( body) ;
468- http:: Response :: from_parts ( parts, body)
467+ let mut response = http:: Response :: from_parts ( parts, body) ;
468+ response. extensions_mut ( ) . insert ( ResponseUrl ( * r. url ) ) ;
469+ response
469470 }
470471}
471472
@@ -482,7 +483,7 @@ mod tests {
482483 use url:: Url ;
483484
484485 use super :: Response ;
485- use crate :: ResponseBuilderExt ;
486+ use crate :: { ResponseBuilderExt , response :: ResponseExt } ;
486487
487488 #[ test]
488489 fn test_from_http_response ( ) {
@@ -497,4 +498,23 @@ mod tests {
497498 assert_eq ! ( response. status( ) , 200 ) ;
498499 assert_eq ! ( * response. url( ) , url) ;
499500 }
501+
502+ #[ test]
503+ fn test_from_http_response_with_url ( ) {
504+ let url = Url :: parse ( "http://example.com" ) . unwrap ( ) ;
505+ let response = Builder :: new ( )
506+ . status ( 200 )
507+ . url ( url. clone ( ) )
508+ . body ( "foo" )
509+ . unwrap ( ) ;
510+ let response = Response :: from ( response) ;
511+
512+ assert_eq ! ( response. status( ) , 200 ) ;
513+ assert_eq ! ( * response. url( ) , url) ;
514+
515+ let http_response = http:: Response :: from ( response) ;
516+ let resp_url = http_response. url ( ) ;
517+ assert_eq ! ( http_response. status( ) , 200 ) ;
518+ assert_eq ! ( resp_url, Some ( & url) ) ;
519+ }
500520}
0 commit comments