Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concept-response-clone: Ensure header guard is cloned after headers #28645

Merged
merged 1 commit into from
Dec 18, 2021

Conversation

negator
Copy link
Contributor

@negator negator commented Dec 17, 2021

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.

// 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())?;

pub fn copy_from_headers(&self, headers: DomRoot<Headers>) -> ErrorResult {
for (name, value) in headers.header_list.borrow().iter() {
self.Append(
ByteString::new(Vec::from(name.as_str())),
ByteString::new(Vec::from(value.as_bytes())),
)?;
}
Ok(())
}

return Err(Error::Type("Guard is immutable".to_string()));


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #___ (GitHub issue number if applicable)
  • There are tests for these changes OR
  • These changes do not require tests because ___

@highfive
Copy link

Heads up! This PR modifies the following files:

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 17, 2021
@highfive
Copy link

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!

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()));
        }
@jdm
Copy link
Member

jdm commented Dec 18, 2021

@bors-servo r+
Thanks!

@bors-servo
Copy link
Contributor

📌 Commit a744ac2 has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Dec 18, 2021
@bors-servo
Copy link
Contributor

⌛ Testing commit a744ac2 with merge 8dc59c6...

@bors-servo
Copy link
Contributor

☀️ Test successful - checks-github, status-taskcluster
Approved by: jdm
Pushing 8dc59c6 to master...

@bors-servo bors-servo merged commit 8dc59c6 into servo:master Dec 18, 2021
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants