From e2e2d42e38107f5d623175eb905e90f9d580369e Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 27 Mar 2017 14:51:10 +0200 Subject: [PATCH] Introduce http_loader::is_redirect_status --- components/net/http_loader.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index ca972034471..f4ee1da4251 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -629,11 +629,7 @@ pub fn http_fetch(request: Rc, // Step 5 match response.actual_response().status { // Code 301, 302, 303, 307, 308 - Some(StatusCode::MovedPermanently) | - Some(StatusCode::Found) | - Some(StatusCode::SeeOther) | - Some(StatusCode::TemporaryRedirect) | - Some(StatusCode::PermanentRedirect) => { + status if status.map_or(false, is_redirect_status) => { response = match request.redirect_mode.get() { RedirectMode::Error => Response::network_error(NetworkError::Internal("Redirect mode error".into())), RedirectMode::Manual => { @@ -1418,3 +1414,15 @@ fn response_needs_revalidation(_response: &Response) -> bool { // TODO this function false } + +/// https://fetch.spec.whatwg.org/#redirect-status +fn is_redirect_status(status: StatusCode) -> bool { + match status { + StatusCode::MovedPermanently | + StatusCode::Found | + StatusCode::SeeOther | + StatusCode::TemporaryRedirect | + StatusCode::PermanentRedirect => true, + _ => false, + } +}