Auto merge of #28634 - negator:patch-1, r=jdm

Preserve URI fragment across redirects

https://www.rfc-editor.org/rfc/rfc7231#section-7.1.2

```
If the Location value provided in a 3xx (Redirection) response does
   not have a fragment component, a user agent MUST process the
   redirection as if the value inherits the fragment component of the
   URI reference used to generate the request target (i.e., the
   redirection inherits the original reference's fragment, if any).
```

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2021-11-30 22:49:53 -05:00 committed by GitHub
commit 79fb5ff6d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -831,7 +831,7 @@ pub fn http_fetch(
} }
// Substep 2-3. // Substep 2-3.
let location = response let mut location = response
.actual_response() .actual_response()
.headers .headers
.get(header::LOCATION) .get(header::LOCATION)
@ -845,6 +845,12 @@ pub fn http_fetch(
}); });
// Substep 4. // 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; response.actual_response_mut().location_url = location;
// Substep 5. // Substep 5.