@@ -54,7 +54,7 @@ pub struct Action {
5454#[ derive( Clone , Debug ) ]
5555pub struct History {
5656 status : StatusCode ,
57- location : Uri ,
57+ uri : Uri ,
5858 previous : Uri ,
5959 headers : HeaderMap ,
6060}
@@ -239,28 +239,39 @@ impl<'a> Attempt<'a> {
239239// ===== impl History =====
240240
241241impl History {
242- /// Returns the redirection response.
242+ /// Get the status code of the redirect response.
243243 #[ inline( always) ]
244244 pub fn status ( & self ) -> StatusCode {
245245 self . status
246246 }
247247
248- /// Returns the headers of the redirection response.
248+ /// Get the URI of the redirect response.
249249 #[ inline( always) ]
250- pub fn headers ( & self ) -> & HeaderMap {
251- & self . headers
250+ pub fn uri ( & self ) -> & Uri {
251+ & self . uri
252252 }
253253
254- /// Returns the destination URI of the redirection .
254+ /// Get the previous URI before the redirect response .
255255 #[ inline( always) ]
256- pub fn location ( & self ) -> & Uri {
257- & self . location
256+ pub fn previous ( & self ) -> & Uri {
257+ & self . previous
258258 }
259259
260- /// Returns the URI of the original request .
260+ /// Get the headers of the redirect response .
261261 #[ inline( always) ]
262- pub fn previous ( & self ) -> & Uri {
263- & self . previous
262+ pub fn headers ( & self ) -> & HeaderMap {
263+ & self . headers
264+ }
265+ }
266+
267+ impl From < & policy:: Attempt < ' _ > > for History {
268+ fn from ( attempt : & policy:: Attempt < ' _ > ) -> Self {
269+ Self {
270+ status : attempt. status ( ) ,
271+ uri : attempt. location ( ) . clone ( ) ,
272+ previous : attempt. previous ( ) . clone ( ) ,
273+ headers : attempt. headers ( ) . clone ( ) ,
274+ }
264275 }
265276}
266277
@@ -393,12 +404,7 @@ impl policy::Policy<Body, BoxError> for FollowRedirectPolicy {
393404 if self . history {
394405 self . history_entries
395406 . get_or_insert_with ( Vec :: new)
396- . push ( History {
397- status : attempt. status ( ) ,
398- location : attempt. location ( ) . clone ( ) ,
399- previous : attempt. previous ( ) . clone ( ) ,
400- headers : attempt. headers ( ) . clone ( ) ,
401- } ) ;
407+ . push ( History :: from ( attempt) ) ;
402408 }
403409
404410 Ok ( policy:: Action :: Follow )
0 commit comments