Skip to content

Commit d55bf28

Browse files
committed
update
1 parent ec6e096 commit d55bf28

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

src/redirect.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct Action {
5454
#[derive(Clone, Debug)]
5555
pub 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

241241
impl 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)

tests/redirect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,13 @@ async fn test_redirect_history() {
503503
let next1 = history.next().unwrap();
504504
assert_eq!(next1.status(), 302);
505505
assert_eq!(next1.previous().path(), "/first");
506-
assert_eq!(next1.location().path(), "/second");
506+
assert_eq!(next1.uri().path(), "/second");
507507
assert_eq!(next1.headers()["location"], "/second");
508508

509509
let next2 = history.next().unwrap();
510510
assert_eq!(next2.status(), 302);
511511
assert_eq!(next2.previous().path(), "/second");
512-
assert_eq!(next2.location().path(), "/dst");
512+
assert_eq!(next2.uri().path(), "/dst");
513513
assert_eq!(next2.headers()["location"], "/dst");
514514

515515
assert!(history.next().is_none());

0 commit comments

Comments
 (0)