Trait ResponseExt
pub trait ResponseExt {
// Required methods
fn get_uri(&self) -> &Uri;
fn get_redirect_history(&self) -> Option<&[Uri]> ⓘ;
}
Available on crate feature
dep_ureq
only.Expand description
Extension trait for http::Response<Body>
.
Adds additional convenience methods to the Response
that are not available
in the plain http API.
Required Methods§
fn get_uri(&self) -> &Uri
fn get_uri(&self) -> &Uri
The Uri that ultimately this Response is about.
This can differ from the request uri when we have followed redirects.
use ureq::ResponseExt;
let res = ureq::get("https://httpbin.org/redirect-to?url=%2Fget")
.call().unwrap();
assert_eq!(res.get_uri(), "https://httpbin.org/get");
fn get_redirect_history(&self) -> Option<&[Uri]> ⓘ
fn get_redirect_history(&self) -> Option<&[Uri]> ⓘ
The full history of uris, including the request and final uri.
Returns None
when Config::save_redirect_history
is false
.
use ureq::ResponseExt;
let uri1: Uri = "https://httpbin.org/redirect-to?url=%2Fget".parse().unwrap();
let uri2: Uri = "https://httpbin.org/get".parse::<Uri>().unwrap();
let res = ureq::get(&uri1)
.config()
.save_redirect_history(true)
.build()
.call().unwrap();
let history = res.get_redirect_history().unwrap();
assert_eq!(history, &[uri1, uri2]);