Add history to response objects (#275)

This allows Error to report both the URL that caused an error, and the
original URL that was requested.

Change unit::connect to use the Response history for tracking number of
redirects, instead of passing the count as a separate parameter.

Incidentally, move handling of the `stream` fully inside `Response`.
Instead of `do_from_read` + `set_stream`, we now have `do_from_stream`,
which takes ownership of the stream and keeps it. We also have
`do_from_request`, which does all of `do_from_stream`, but also sets the
`previous` field.
This commit is contained in:
Jacob Hoffman-Andrews
2020-12-13 11:59:11 -08:00
committed by GitHub
parent 10baf7c051
commit 8cb4f401e3
4 changed files with 143 additions and 53 deletions

View File

@@ -118,8 +118,7 @@ impl Request {
}
let reader = payload.into_read();
let unit = Unit::new(&self.agent, &self.method, &url, &self.headers, &reader);
let response =
unit::connect(unit, true, 0, reader, false).map_err(|e| e.url(url.clone()))?;
let response = unit::connect(unit, true, reader, None).map_err(|e| e.url(url.clone()))?;
if self.error_on_non_2xx && response.status() >= 400 {
Err(Error::Status(response.status(), response))