Skip to content

Commit

Permalink
concept-response-clone: Ensure header guard is cloned after headers
Browse files Browse the repository at this point in the history
https://fetch.spec.whatwg.org/#concept-response-clone

If the header guard of the response to clone is `immutable`, then copying the headers to the new response will fail with `Guard is immutable` unless we ensure the guard is copied _after_ the headers.

https://github.com/servo/servo/blob/8650794391729c6fee34bc2644ccbb85bd8fd58d/components/script/dom/response.rs#L331-L334

    fn Append(&self, name: ByteString, value: ByteString) -> ErrorResult {
        // Step 1
        let value = normalize_value(value);
        // Step 2
        let (mut valid_name, valid_value) = validate_name_and_value(name, value)?;
        valid_name = valid_name.to_lowercase();
        // Step 3
        if self.guard.get() == Guard::Immutable {
            return Err(Error::Type("Guard is immutable".to_string()));
        }
  • Loading branch information
negator committed Dec 17, 2021
1 parent 8650794 commit a744ac2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion components/script/dom/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ impl ResponseMethods for Response {

// Step 2
let new_response = Response::new(&self.global());
new_response.Headers().set_guard(self.Headers().get_guard());
new_response.Headers().copy_from_headers(self.Headers())?;
new_response.Headers().set_guard(self.Headers().get_guard());

// https://fetch.spec.whatwg.org/#concept-response-clone
// Instead of storing a net_traits::Response internally, we
Expand Down

0 comments on commit a744ac2

Please sign in to comment.