From d6ca82cec28315296761daeecd75a503de238eb7 Mon Sep 17 00:00:00 2001 From: Naveen Gattu Date: Sun, 28 Nov 2021 21:29:25 -0800 Subject: [PATCH 1/4] preserve fragment --- components/net/http_loader.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index 4b42355b067..f66fc4c6363 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -844,8 +844,15 @@ pub fn http_fetch( .ok() }); - // Substep 4. - response.actual_response_mut().location_url = location; + // Substep 4. + response.actual_response_mut().location_url = location.map(|res| res.map(|mut url| { + let current_url = request.current_url(); + let current_fragment = current_url.fragment(); + if url.fragment().is_none() && current_fragment.is_some() { + url.set_fragment(current_fragment); + } + url + })); // Substep 5. response = match request.redirect_mode { From 49ea36399de10495939d8be3958893ec42e06370 Mon Sep 17 00:00:00 2001 From: Naveen Gattu Date: Sun, 28 Nov 2021 21:47:36 -0800 Subject: [PATCH 2/4] more concise --- components/net/http_loader.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index f66fc4c6363..4f8824ae7ea 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -847,11 +847,10 @@ pub fn http_fetch( // Substep 4. response.actual_response_mut().location_url = location.map(|res| res.map(|mut url| { let current_url = request.current_url(); - let current_fragment = current_url.fragment(); - if url.fragment().is_none() && current_fragment.is_some() { - url.set_fragment(current_fragment); + match (current_url.fragment(), url.fragment()) { + (fragment @ Some(..), None) => { url.set_fragment(fragment); url }, + _ => url } - url })); // Substep 5. From 733019e029e069d930bee760836a9af8725600f8 Mon Sep 17 00:00:00 2001 From: Naveen Gattu Date: Mon, 29 Nov 2021 06:50:30 -0800 Subject: [PATCH 3/4] if let destructuring --- components/net/http_loader.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index 4f8824ae7ea..ac19dd28ef4 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -831,7 +831,7 @@ pub fn http_fetch( } // Substep 2-3. - let location = response + let mut location = response .actual_response() .headers .get(header::LOCATION) @@ -845,13 +845,15 @@ pub fn http_fetch( }); // Substep 4. - response.actual_response_mut().location_url = location.map(|res| res.map(|mut url| { - let current_url = request.current_url(); - match (current_url.fragment(), url.fragment()) { - (fragment @ Some(..), None) => { url.set_fragment(fragment); url }, - _ => url + if let Some(ref mut location) = location { + if let Ok(ref mut location) = location { + if location.fragment().is_none() { + let current_url = request.current_url(); + location.set_fragment(current_url.fragment()); + } } - })); + } + response.actual_response_mut().location_url = location; // Substep 5. response = match request.redirect_mode { From 94ea42240414b538f96a290cd853f01d59bb79f3 Mon Sep 17 00:00:00 2001 From: Naveen Gattu Date: Mon, 29 Nov 2021 06:59:30 -0800 Subject: [PATCH 4/4] more concise --- components/net/http_loader.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index ac19dd28ef4..db91c15c3cc 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -844,13 +844,11 @@ pub fn http_fetch( .ok() }); - // Substep 4. - if let Some(ref mut location) = location { - if let Ok(ref mut location) = location { - if location.fragment().is_none() { - let current_url = request.current_url(); - location.set_fragment(current_url.fragment()); - } + // Substep 4. + if let Some(Ok(ref mut location)) = location { + if location.fragment().is_none() { + let current_url = request.current_url(); + location.set_fragment(current_url.fragment()); } } response.actual_response_mut().location_url = location;