Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement the Request API #12700
Implement the Request API #12700
Conversation
highfive
commented
Aug 2, 2016
|
Heads up! This PR modifies the following files:
|
highfive
commented
Aug 2, 2016
|
r? @jdm |
| return Ok(()); | ||
| } | ||
| // Step 6 | ||
| if self.guard == Guard::Response && is_forbidden_response_header(&valid_name) { | ||
| if *self.guard.borrow() == Guard::Response && is_forbidden_response_header(&valid_name) { |
This comment has been minimized.
This comment has been minimized.
KiChjang
Aug 2, 2016
Member
This method (Append) here and Delete, Set could really use a match expression instead of using so many ifs. Something like the following:
match *self.guard.borrow() {
Guard::Immutable => Err(Error::Type("Guard is immutable".to_owned())),
Guard::Request if is_forbidden_header_name(&valid_name) => Ok(()),
// ... and so on...
}
This comment has been minimized.
This comment has been minimized.
jdm
Aug 2, 2016
Member
I disagree here - I find it easier to follow the logic and match it against the specification when it's split up the way it is.
| impl Headers { | ||
| pub fn set_guard(&self, new_guard: Guard) { | ||
| let mut borrowed_guard = self.guard.borrow_mut(); | ||
| replace(&mut *borrowed_guard, new_guard); |
This comment has been minimized.
This comment has been minimized.
|
|
||
| pub fn get_guard(&self) -> Guard { | ||
| let borrowed_guard = self.guard.borrow(); | ||
| return borrowed_guard.clone(); |
This comment has been minimized.
This comment has been minimized.
KiChjang
Aug 2, 2016
•
Member
Not sure what the purpose is in getting a guard here, but a reference to self.guard.borrow() should be returned instead. Cloning here means that the Guard returned is a completely different object than the Guard in self.guard. Also, return can be omitted here.
|
|
||
| pub fn empty_header_list(&self) { | ||
| let mut borrowed_header_list = self.header_list.borrow_mut(); | ||
| replace(&mut *borrowed_header_list, HyperHeaders::new()); |
This comment has been minimized.
This comment has been minimized.
| use dom::headers::{Headers, Guard}; | ||
| use hyper; | ||
| use msg; | ||
| use net_traits::request as NetTraitsRequest; |
This comment has been minimized.
This comment has been minimized.
KiChjang
Aug 2, 2016
Member
I believe you can do use net_traits::request::{Request as NetTraitsRequest, Origin, Window};. Can also add in any other struct/enum that you need from net_traits/request.rs
| url: url::Url, | ||
| origin: Option<NetTraitsRequest::Origin>, | ||
| is_service_worker_global_scope: bool, | ||
| pipeline_id: Option<msg::constellation_msg::PipelineId>) -> Root<Request> { |
This comment has been minimized.
This comment has been minimized.
KiChjang
Aug 2, 2016
Member
use msg::constellation_msg::PipelineId above and you can simply use PipelineId here.
| init: &RequestInit) | ||
| -> Fallible<Root<Request>> { | ||
| let mut request = | ||
| NetTraitsRequest::Request::new(url::Url::parse("").unwrap(), |
This comment has been minimized.
This comment has been minimized.
|
I know I've left a lot of comments, but this is really great work! Most of my comments are about idiomatic usage of RefCell/Cell and reducing unnecessary cloning. Reviewed 3 of 3 files at r1, 2 of 2 files at r2, 1 of 1 files at r3, 2 of 2 files at r4, 3 of 4 files at r5, 1 of 1 files at r9, 1 of 1 files at r10, 1 of 1 files at r11, 1 of 2 files at r13, 1 of 2 files at r14, 1 of 1 files at r15. components/script/dom/headers.rs, line 21 [r10] (raw file):
This can be components/script/dom/headers.rs, line 27 [r14] (raw file):
This can include Copy as well. components/script/dom/headers.rs, line 210 [r14] (raw file):
Let's do components/script/dom/request.rs, line 33 [r5] (raw file):
We should add one, in that case! components/script/dom/request.rs, line 35 [r5] (raw file):
This can be a components/script/dom/request.rs, line 36 [r5] (raw file):
Let's call this components/script/dom/request.rs, line 60 [r5] (raw file):
No need for this to be public. components/script/dom/request.rs, line 94 [r5] (raw file):
I have filed whatwg/fetch#351 to sort out what we should actually be doing here. components/script/dom/request.rs, line 61 [r15] (raw file):
We should obtain an origin based on the URL of the GlobalRef instead of accepting it as an argument here. components/script/dom/request.rs, line 63 [r15] (raw file):
We should use components/script/dom/request.rs, line 93 [r15] (raw file):
We should share this code with the same code in new_inherited. components/script/dom/request.rs, line 103 [r15] (raw file):
No need for Cell outside of data structures. This can be a regular components/script/dom/request.rs, line 121 [r15] (raw file):
components/script/dom/request.rs, line 129 [r15] (raw file):
components/script/dom/request.rs, line 131 [r15] (raw file):
components/script/dom/request.rs, line 142 [r15] (raw file):
These two lines can be combined. components/script/dom/request.rs, line 146 [r15] (raw file):
These two lines can be combined. components/script/dom/request.rs, line 150 [r15] (raw file):
We can approximate this for now by using components/script/dom/request.rs, line 159 [r15] (raw file):
components/script/dom/request.rs, line 168 [r15] (raw file):
components/script/dom/request.rs, line 188 [r15] (raw file):
If we can't use components/script/dom/request.rs, line 194 [r15] (raw file):
Use components/script/dom/request.rs, line 196 [r15] (raw file):
components/script/dom/request.rs, line 198 [r15] (raw file):
components/script/dom/request.rs, line 203 [r15] (raw file):
This seems to be unused. components/script/dom/request.rs, line 205 [r15] (raw file):
We shouldn't need to clone this here; we can borrow it instead. components/script/dom/request.rs, line 232 [r15] (raw file):
components/script/dom/request.rs, line 242 [r15] (raw file):
components/script/dom/request.rs, line 247 [r15] (raw file):
We can write this as components/script/dom/request.rs, line 259 [r15] (raw file):
Let's use components/script/dom/request.rs, line 265 [r15] (raw file):
Same transformation is possible as mode. components/script/dom/request.rs, line 282 [r15] (raw file):
components/script/dom/request.rs, line 284 [r15] (raw file):
components/script/dom/request.rs, line 298 [r15] (raw file):
components/script/dom/request.rs, line 303 [r15] (raw file):
No need to clone this value until necessary. components/script/dom/request.rs, line 312 [r15] (raw file):
The components/script/dom/request.rs, line 316 [r15] (raw file):
components/script/dom/request.rs, line 321 [r15] (raw file):
Let's make a Request constructor method that accepts a components/script/dom/request.rs, line 331 [r15] (raw file):
Let's add a components/script/dom/request.rs, line 334 [r15] (raw file):
components/script/dom/request.rs, line 337 [r15] (raw file):
components/script/dom/request.rs, line 345 [r15] (raw file):
components/script/dom/request.rs, line 348 [r15] (raw file):
components/script/dom/request.rs, line 350 [r15] (raw file):
I think this can be components/script/dom/request.rs, line 355 [r15] (raw file):
components/script/dom/request.rs, line 358 [r15] (raw file):
components/script/dom/request.rs, line 363 [r15] (raw file):
This overwrites the original, which would undo the guard modification we made previously. We should add a method to components/script/dom/request.rs, line 367 [r15] (raw file):
let input_body = if let RequestInfo::Request(input_request) = input {
input_request.request.borrow().body.clone()
} else {
None
};components/script/dom/request.rs, line 377 [r15] (raw file):
components/script/dom/request.rs, line 403 [r15] (raw file):
components/script/dom/request.rs, line 406 [r15] (raw file):
Let's remove this until it's needed. components/script/dom/request.rs, line 416 [r15] (raw file):
components/script/dom/request.rs, line 419 [r15] (raw file):
components/script/dom/request.rs, line 440 [r15] (raw file):
Let's call this components/script/dom/request.rs, line 524 [r15] (raw file):
This should delegate to request_is_disturbed. components/script/dom/request.rs, line 530 [r15] (raw file):
This should delegate to request_is_locked. components/script/dom/request.rs, line 538 [r15] (raw file):
let r = self.request.borrow();
let m = r.method.borrow();
ByteString::new(m.as_ref().as_bytes().into());components/script/dom/request.rs, line 544 [r15] (raw file):
let r = self.request.borrow();
USVString(r.url_list.borrow().get(0).map_or("", |u| u.as_str()).into())components/script/dom/request.rs, line 550 [r15] (raw file):
We should make a constructor method for Headers that has no initializer argument and is infallible. This will let us remove the unwrap. components/script/dom/request.rs, line 556 [r15] (raw file):
components/script/dom/request.rs, line 562 [r15] (raw file):
components/script/dom/request.rs, line 569 [r15] (raw file):
USVString(match *self.request.borrow().referer.borrow() {
Referer::NoReferer => String::from("no-referrer"),
...
})components/script/dom/request.rs, line 580 [r15] (raw file):
components/script/dom/request.rs, line 589 [r15] (raw file):
components/script/dom/request.rs, line 614 [r15] (raw file):
components/script/dom/request.rs, line 625 [r15] (raw file):
No need for the &. components/script/dom/request.rs, line 633 [r15] (raw file):
components/script/dom/request.rs, line 639 [r15] (raw file):
This should use components/script/dom/request.rs, line 640 [r15] (raw file):
Let's add a components/script/dom/request.rs, line 647 [r15] (raw file):
This should use components/script/dom/request.rs, line 652 [r15] (raw file):
Whoops, when suggesting a bunch of changes earlier I missed that we need to translate between enum types as well. Be sure to add components/script/dom/request.rs, line 797 [r15] (raw file):
That's because https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer has a step that deals with "the empty string" case. components/script/dom/request.rs, line 799 [r15] (raw file):
See whatwg/fetch#342 and whatwg/fetch#346 Comments from Reviewable |
Enable Request API and Response API tests <!-- Please describe your changes on the following line: --> This will enable the Request API and Response API tests, which will be useful for PR #12700 and the future PR regarding the Response API. --- <!-- 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: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- 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/12722) <!-- Reviewable:end -->
|
components/script/dom/headers.rs, line 21 [r10] (raw file):
|
|
Derive JSTraceable and HeapSizeOf for the Guard enum. |
Enable Request API and Response API tests <!-- Please describe your changes on the following line: --> This will enable the Request API and Response API tests, which will be useful for PR #12700 and the future PR regarding the Response API. --- <!-- 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: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- 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/12722) <!-- Reviewable:end -->
|
@bors-servo: try |
Implement the Request API <!-- Please describe your changes on the following line: --> This PR implements the [Request API](https://fetch.spec.whatwg.org/#request-class) for the Fetch API, including its attributes and constructor, and introduces changes in relevant files. This Request integrates `net_traits::request::Request` and `dom::headers`. There are few related TODOs and comments: 1. `net_traits::request::Request`'s `headers` field does not point to `dom::request::Request`'s `headers_reflector`. 2. Every Constructor step that involves `Readable Stream` object is not implemented. 3. Every Constructor step that involves `entry settings object` or `environment settings object` is not implemented. 4. `./mach build -d` does not report any error, but prints a few warnings about unused variables related to (1) and (2). 5. Enum `ReferrerPolicy` generated by `RequestBinding` does not match `net_traits::request::Request`'s implementation. 6. `Promise`s in Body webidl are commented out. --- <!-- 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 - [X] These changes fix #11895 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because tests for the Request API already exists, but this commit does not implement the interface fully. <!-- 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/12700) <!-- Reviewable:end -->
|
|
|
components/script/dom/request.rs, line 614 [r15] (raw file):
|
|
components/script/dom/request.rs, line 544 [r15] (raw file):
Comments from Reviewable |
|
Looks like lots of test results need updating, and a couple new failures that need to be addressed:
In particular, |
01e760d
to
b541a7a
|
Getting close! There are a couple older comments that are still unaddressed, too. Reviewed 15 of 15 files at r29. components/script/dom/headers.rs, line 87 [r29] (raw file):
components/script/dom/headers.rs, line 179 [r29] (raw file):
The specification was updated to remove the copying here, so components/script/dom/headers.rs, line 370 [r29] (raw file):
These should be components/script/dom/request.rs, line 52 [r29] (raw file):
There are unused arguments here, right? components/script/dom/request.rs, line 239 [r29] (raw file):
Does this need to be mutable? components/script/dom/request.rs, line 308 [r29] (raw file):
Where is this used? components/script/dom/request.rs, line 317 [r29] (raw file):
It would be clearer to phrase this as components/script/dom/request.rs, line 320 [r29] (raw file):
This could panic if the input request doesn't have any headers. Let's do components/script/dom/request.rs, line 354 [r29] (raw file):
let input_body = if let RequestInfo::Request(input_request) = input {
let request = input_request.request.borrow();
request.body.borrow().clone()
else {
None
};components/script/dom/request.rs, line 402 [r29] (raw file):
This isn't right; we should be taking the URL from the NetTraitsRequest object. Comments from Reviewable |
|
Great work! Please squash these into a single commit except for "Modify Headers API to correctly validate value", which makes sense as an independent one. Reviewed 2 of 2 files at r30. Comments from Reviewable |
This commit adds new files related to implementing the [Request API](https://fetch.spec.whatwg.org/#request-class). This commit also changes the expected web platform tests results. It also modifies the following files: components/net_traits/request.rs HeapSizeOf is implemented in net_traits/request so that dom::request can be used as a wrapper around net_traits::request::Request. components/script/dom/headers.rs Several methods are added to Headers so that request can access and modify some of the headers fields.
This commit modifies the headers API script to correctly validate value. As a result of this change, more wpt tests pass. The commit also changes the expected test results.
|
@bors-servo: r+ |
|
|
Implement the Request API <!-- Please describe your changes on the following line: --> This PR implements the [Request API](https://fetch.spec.whatwg.org/#request-class) for the Fetch API, including its attributes and constructor, and introduces changes in relevant files. This Request integrates `net_traits::request::Request` and `dom::headers`. There are few related TODOs and comments: 1. `net_traits::request::Request`'s `headers` field does not point to `dom::request::Request`'s `headers_reflector`. 2. Every Constructor step that involves `Readable Stream` object is not implemented. 3. Every Constructor step that involves `entry settings object` or `environment settings object` is not implemented. 4. `./mach build -d` does not report any error, but prints a few warnings about unused variables related to (1) and (2). 5. Enum `ReferrerPolicy` generated by `RequestBinding` does not match `net_traits::request::Request`'s implementation. 6. `Promise`s in Body webidl are commented out. --- <!-- 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 - [X] These changes fix #11895 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because tests for the Request API already exists, but this commit does not implement the interface fully. <!-- 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/12700) <!-- Reviewable:end -->
|
|
jeenalee commentedAug 2, 2016
•
edited by larsbergstrom
This PR implements the Request API for the Fetch API, including its attributes and constructor, and introduces changes in relevant files.
This Request integrates
net_traits::request::Requestanddom::headers.There are few related TODOs and comments:
net_traits::request::Request'sheadersfield does not point todom::request::Request'sheaders_reflector.Readable Streamobject is not implemented.entry settings objectorenvironment settings objectis not implemented../mach build -ddoes not report any error, but prints a few warnings about unused variables related to (1) and (2).ReferrerPolicygenerated byRequestBindingdoes not matchnet_traits::request::Request's implementation.Promises in Body webidl are commented out../mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is