Repository navigation
Add the append method for the Headers API - #12467
Conversation
|
Heads up! This PR modifies the following files:
|
|
r? @jdm |
|
Good start! I've left some comments on ways I think we can make the code more readable. Reviewed 6 of 6 files at r1, 1 of 1 files at r2. components/script/dom/headers.rs, line 39 [r2] (raw file):
This should be called components/script/dom/headers.rs, line 61 [r2] (raw file):
Rather than writing out comments that duplicate specification text, we should use components/script/dom/headers.rs, line 66 [r2] (raw file):
let name_string = match String::from_utf8(name.into()) {
Ok(ns) => ns,
_ => return Err(Error::Type("Non-UTF8 header name found".into()));
};components/script/dom/headers.rs, line 67 [r2] (raw file):
I think this header group abstraction makes it harder to reason about what this code is actually checking. I'd prefer to have each step written out like in the spec. components/script/dom/headers.rs, line 86 [r2] (raw file):
components/script/dom/headers.rs, line 95 [r2] (raw file):
This isn't used by append. components/script/dom/headers.rs, line 102 [r2] (raw file):
What's left to do? components/script/dom/headers.rs, line 108 [r2] (raw file):
What does this correspond to in the specification? Append doesn't appear to check for these. components/script/dom/headers.rs, line 120 [r2] (raw file):
components/script/dom/headers.rs, line 128 [r2] (raw file):
components/script/dom/headers.rs, line 129 [r2] (raw file):
If we could merge this with https://dxr.mozilla.org/servo/rev/4cc4bc3c38eff22f9472215261d6926315b42f8d/components/script/dom/xmlhttprequest.rs#416 that would be great. The code there is shorter; I think it would be good to replace this implementation with that one, and have that one call into this one. components/script/dom/headers.rs, line 198 [r2] (raw file):
Let's make this method return components/script/dom/headers.rs, line 202 [r2] (raw file):
We can have a more specific error message if we do: if !is_field_name(name) {
return Err(...);
}
if !is_field_content(value) {
return Err(...);
}
Ok(())components/script/dom/headers.rs, line 220 [r2] (raw file):
Add a comment linking to https://fetch.spec.whatwg.org/#concept-header-value-normalize components/script/dom/headers.rs, line 222 [r2] (raw file):
What about this instead? match (index_of_first_non_whitespace(&value), index_of_last_non_whitespace(&value)) {
(Some(begin), Some(end)) => ByteString::new(value[begin..end].to_owned()),
_ => ByteString::new(),
}components/script/dom/headers.rs, line 255 [r2] (raw file):
This can be written as: fn is_HTTP_whitespace(byte: u8) -> bool {
byte == b'\t' || byte == b'\n' || byte == b'\r' || b == ' '
}components/script/dom/headers.rs, line 263 [r2] (raw file):
Let's write this as: if !is_HTTP_whitespace(byte) {
return Some(index);
}components/script/dom/headers.rs, line 273 [r2] (raw file):
Same previous comment. components/script/dom/headers.rs, line 284 [r2] (raw file):
components/script/dom/headers.rs, line 310 [r2] (raw file):
This can be components/script/dom/headers.rs, line 314 [r2] (raw file):
This can be components/script/dom/headers.rs, line 322 [r2] (raw file):
components/script/dom/headers.rs, line 325 [r2] (raw file):
Let's use components/script/dom/headers.rs, line 326 [r2] (raw file):
Could we phrase the checks in this function more like components/script/dom/headers.rs, line 327 [r2] (raw file):
Can we reuse is_obs_text here? components/script/dom/webidls/Headers.webidl, line 5 [r2] (raw file):
tests/unit/script/headers.rs, line 14 [r2] (raw file):
It will be easier to read if these are called tests/unit/script/headers.rs, line 20 [r2] (raw file):
tests/unit/script/headers.rs, line 23 [r2] (raw file):
Same naming comment for all the tests. tests/unit/script/headers.rs, line 29 [r2] (raw file):
We can use Comments from Reviewable |
|
AFAIK the spec links should be outside the functions, not inside. |
83cab57 to
861a5a2
Compare
servo#12467 - Add appropriate spec links - Remove unnecessary code that is not used by append method - Simplify code to read more easily
|
Thanks for addressing those comments! There are still some unaddressed ones in the unit tests, and I've left some new ones. Reviewed 1 of 1 files at r4, 3 of 3 files at r5. components/script/dom/headers.rs, line 62 [r5] (raw file):
I still find the following code more readable than the header group abstraction: // Step 3
if self.guard == Guard::Immutable {
return ...;
}
// Step 4
if self.guard == Guard::Request && is_forbidden_header_name(valid_name) {
return ...;
}components/script/dom/headers.rs, line 123 [r5] (raw file):
Instead of components/script/dom/headers.rs, line 176 [r5] (raw file):
No need for components/script/dom/headers.rs, line 205 [r5] (raw file):
We should return Comments from Reviewable |
|
components/script/dom/headers.rs, line 205 [r5] (raw file):
|
|
|
||
| fn index_of_last_non_whitespace(value: &ByteString) -> Option<usize> { | ||
| for (index, &byte) in value.iter().enumerate().rev() { | ||
| if !is_HTTP_whitespace(byte) { |
There was a problem hiding this comment.
We can use even more iterator magic here!
value.iter().enumerate().rev().find(|_,v| !is_whitespace(v)).map(|i| i.0|)
something like that.
But it's good as is too, some folks prefer to avoid overusing iterator adapters.
|
Review status: all files reviewed at latest revision, 10 unresolved discussions. components/script/dom/headers.rs, line 205 [r5] (raw file):
|
|
Almost there! Please go ahead and squash all the changes together into a single commit, as well. I don't think we gain much from having the independent commits when they're all part of implementing a single feature. Reviewed 3 of 3 files at r6. components/script/dom/headers.rs, line 129 [r2] (raw file):
|
This commit will add the append method and associated helper functions, and introduce any necessary changes for it.
8f4d953 to
530b027
Compare
Add the append method for the Headers API <!-- Please describe your changes on the following line: --> This commit adds the append method for the Headers API. @malisas and I are both contributors. There are a few TODOs related: - The script needs to parse the header value for certain header names to decide the header group it belongs - There are possible spec bugs that could change what a valid header value looks like (related: [issue page](whatwg/fetch#332)) There are WPT tests already written for the Headers API, but they will fail as the Headers API is not fully implemented. --- <!-- 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 - [X] These changes do not require tests because tests for the Headers API already exists, but this commit does not implement the interface fully. The tests will fail. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12467) <!-- Reviewable:end -->
|
💔 Test failed - linux-rel |
We'll need to add the Headers interface name to the list in |
| "FocusEvent", | ||
| "FormData", | ||
| "HashChangeEvent", | ||
| "Headers", |
There was a problem hiding this comment.
This won't work yet, since the Exposed=(Window,Worker) annotation is commented out.
|
@bors-servo: r+ |
|
📌 Commit 094995b has been approved by |
Expose the Headers interface to the Window scope and to Workers Move Append function inside HeadersMethods trait
094995b to
272d12d
Compare
|
@bors-servo: r+ |
|
📌 Commit 272d12d has been approved by |
Add the append method for the Headers API <!-- Please describe your changes on the following line: --> This commit adds the append method for the Headers API. @malisas and I are both contributors. There are a few TODOs related: - The script needs to parse the header value for certain header names to decide the header group it belongs - There are possible spec bugs that could change what a valid header value looks like (related: [issue page](whatwg/fetch#332)) There are WPT tests already written for the Headers API, but they will fail as the Headers API is not fully implemented. --- <!-- 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 - [X] These changes do not require tests because tests for the Headers API already exists, but this commit does not implement the interface fully. The tests will fail. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12467) <!-- Reviewable:end -->
|
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows-dev |
Headers API constructor and methods <!-- Please describe your changes on the following line: --> This PR fills out the constructor and the delete, get, has, and set methods for the Headers API. Addresses issue #11897 . The PR also rewrites the append method to support `hyper::header::Headers`'s HashMap `insert` method, which overwrites entries instead of appending. As a result of this, for a given header name there is at most one value in the inner "header list"/HashMap. Multiple values for the same name are comma-delimited. There are still a few TODOs: - Support `OpenEndedDictionary<ByteString>` as a possible `HeadersInit` value. [OpenEndedDictionary<T> is a future IDL construct.](https://fetch.spec.whatwg.org/#headers-class) - Support `iterable<ByteString, ByteString>`. Related issue: #12628 - Values are comma-delimited, except for values with the name `set-cookie`, which are newline-delimited. This is because values for `set-cookie` are [allowed to contain](https://tools.ietf.org/html/rfc7230#section-3.2.2) inner commas. This violates the [spec](https://fetch.spec.whatwg.org/#concept-header-value-combined). - The TODOs from PR #12467 regarding value parsing also still need to be resolved. --- <!-- 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 - [X] These changes do not require tests because tests for the Headers API already exists, but this commit does not implement the interface fully. The tests will fail. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12634) <!-- Reviewable:end -->
Headers API constructor and methods <!-- Please describe your changes on the following line: --> This PR fills out the constructor and the delete, get, has, and set methods for the Headers API. Addresses issue #11897 . The PR also rewrites the append method to support `hyper::header::Headers`'s HashMap `insert` method, which overwrites entries instead of appending. As a result of this, for a given header name there is at most one value in the inner "header list"/HashMap. Multiple values for the same name are comma-delimited. There are still a few TODOs: - Support `OpenEndedDictionary<ByteString>` as a possible `HeadersInit` value. [OpenEndedDictionary<T> is a future IDL construct.](https://fetch.spec.whatwg.org/#headers-class) - Support `iterable<ByteString, ByteString>`. Related issue: #12628 - Values are comma-delimited, except for values with the name `set-cookie`, which are newline-delimited. This is because values for `set-cookie` are [allowed to contain](https://tools.ietf.org/html/rfc7230#section-3.2.2) inner commas. This violates the [spec](https://fetch.spec.whatwg.org/#concept-header-value-combined). - The TODOs from PR #12467 regarding value parsing also still need to be resolved. --- <!-- 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 - [X] These changes do not require tests because tests for the Headers API already exists, but this commit does not implement the interface fully. The tests will fail. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12634) <!-- Reviewable:end -->
This commit adds the append method for the Headers API. @malisas and I are both contributors.
There are a few TODOs related:
There are WPT tests already written for the Headers API, but they will fail as the Headers API is not fully implemented.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is