Skip to content

Update fetch methods - #17521

Merged
bors-servo merged 10 commits into
servo:masterfrom
KiChjang:update-fetch
Aug 19, 2017
Merged

bors-servo merged 10 commits into
servo:masterfrom
KiChjang:update-fetch

Conversation

@KiChjang

@KiChjang KiChjang commented Jun 26, 2017 •

Copy link
Copy Markdown
Contributor

Includes updates to main fetch, scheme fetch, HTTP fetch, HTTP-redirect fetch, HTTP-network fetch, HTTP-network-or-cache fetch and CORS preflight fetch.


This change is Reviewable

@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @KiChjang: components/net_traits/response.rs, components/net_traits/response.rs, components/net/fetch/methods.rs, components/net/websocket_loader.rs, components/net_traits/request.rs and 2 more

@highfive

Copy link
Copy Markdown

warning Warning warning

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

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jun 26, 2017
@jdm jdm assigned jdm and unassigned pcwalton Jun 26, 2017

if (same_origin && !cors_flag ) ||
current_url.scheme() == "data" ||
current_url.scheme() == "file" ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am 99% sure this is going to hit the same problem as #14515 (comment) .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How unfortunate. Looks like I'll have to drop those changes then.

@KiChjang

Copy link
Copy Markdown
Contributor Author

Huh... looks like this update failed some unit tests, will look into them.

@KiChjang
KiChjang force-pushed the update-fetch branch 5 times, most recently from 927d099 to 81fa345 Compare July 1, 2017 21:29
@KiChjang

KiChjang commented Jul 2, 2017

Copy link
Copy Markdown
Contributor Author

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 81fa345 with merge aaccbce...

bors-servo pushed a commit that referenced this pull request Jul 2, 2017
Update fetch methods

Includes updates to main fetch, scheme fetch, HTTP fetch, HTTP-redirect fetch, HTTP-network fetch, HTTP-network-or-cache fetch and CORS preflight fetch.

<!-- 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/17521)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Jul 2, 2017
@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Jul 2, 2017
@KiChjang

KiChjang commented Jul 3, 2017 •

Copy link
Copy Markdown
Contributor Author

I found out what's wrong with the tests, and it's because of the redirection code that lives in network_listener.rs. Since http_redirect_fetch does not check the headers to see whether there is a Location header anymore, we will need to create a location_url field on ResponseInit that the code creates to be fed into http_redirect_fetch. I'm currently stuck on that, because location_url needs to implement serde::Serialize and serde::Deserialize, which means url::ParseError needs to have those implementations as well, but it is not quite simple implementing those two traits on url::ParseError.

@KiChjang
KiChjang force-pushed the update-fetch branch 2 times, most recently from 677a5ce to 65c1409 Compare July 5, 2017 04:50
@KiChjang

KiChjang commented Jul 5, 2017

Copy link
Copy Markdown
Contributor Author

Ok, instead of storing an Option<Result<ServoUrl, url::ParseError>>, I'm replacing the ParseError with a String.

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 65c1409 with merge dc3171dde971e2c160f211010dcc82af930c1be3...

@bors-servo

Copy link
Copy Markdown
Contributor

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this work!

Comment thread components/net/fetch/methods.rs Outdated
match header_names {
// Subsubstep 2.
Some(list) if request.credentials_mode != CredentialsMode::Include => {
if list.iter().any(|s| **s == "*".to_owned()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be checking if list.len() == 1 and the first element is "*".

Comment thread components/net/fetch/methods.rs Outdated
}

pub fn is_simple_method(m: &Method) -> bool {
// https://fetch.spec.whatwg.org/#cors-safelisted-method

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

///

// Step 7
let same_origin = location_url.origin()== request.current_url().origin();
// FIXME: Correctly use request's origin
let same_origin = location_url.origin() == request.current_url().origin();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the correct origin here. We can create an ImmutableOrigin value from the url's origin and compare them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That shouldn't be neccessary either. All code paths that come from RequestInit should already have an ImmutableOrigin set for them.

// Step 11
if response.actual_response().status.map_or(false, |code|
((code == StatusCode::MovedPermanently || code == StatusCode::Found) && request.method == Method::Post) ||
code == StatusCode::SeeOther) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this change is an improvement. I found it easier to read the code before.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The improvement here is that the code doesn't panic when it encounters a None on the status field of the actual response.

// TODO: Prompt the user for proxy authentication credentials
// Wrong, but will have to do until we are able to prompt the user
// otherwise this creates an infinite loop
// We basically pretend that the user declined to enter credentials

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is incorrect if we don't return response like the old code did.

preflight.initiator = request.initiator.clone();
preflight.type_ = request.type_.clone();
preflight.destination = request.destination.clone();
preflight.origin = request.origin.clone();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Comment thread components/net/http_loader.rs Outdated
// Substep 4
// Substep 5
if (methods.iter().any(|m| m.as_ref() == "*") ||
header_names.iter().any(|hn| **hn == "*".to_owned())) &&

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do ***hn == "*" instead?

Comment thread components/net/http_loader.rs Outdated
// Substep 6
// Substep 8
if request.headers.iter().any(
|header| header.name().to_ascii_lowercase() == "authorization" &&

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for lowercasing; UniCase ignores string case when comparing.

Comment thread components/net/http_loader.rs Outdated
// Substep 8
if request.headers.iter().any(
|header| header.name().to_ascii_lowercase() == "authorization" &&
header_names.iter().all(|hn| *hn != UniCase(header.name().to_owned()))) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do UniCase(header.name()) instead?

@jdm

jdm commented Aug 18, 2017

Copy link
Copy Markdown
Member

This can r=me with the WIP commit merged into the original related change.

@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Aug 18, 2017
@KiChjang

Copy link
Copy Markdown
Contributor Author

@bors-servo r=jdm

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 268f78e 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 Aug 18, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 268f78e with merge 35f99c3...

bors-servo pushed a commit that referenced this pull request Aug 18, 2017
Update fetch methods

Includes updates to main fetch, scheme fetch, HTTP fetch, HTTP-redirect fetch, HTTP-network fetch, HTTP-network-or-cache fetch and CORS preflight fetch.

<!-- 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/17521)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-wpt3

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Aug 18, 2017
@KiChjang

Copy link
Copy Markdown
Contributor Author

@bors-servo retry

  • infra

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 268f78e with merge 9f64630...

bors-servo pushed a commit that referenced this pull request Aug 18, 2017
Update fetch methods

Includes updates to main fetch, scheme fetch, HTTP fetch, HTTP-redirect fetch, HTTP-network fetch, HTTP-network-or-cache fetch and CORS preflight fetch.

<!-- 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/17521)
<!-- Reviewable:end -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Aug 18, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: jdm
Pushing 9f64630 to master...

@bors-servo
bors-servo merged commit 268f78e into servo:master Aug 19, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Aug 19, 2017
@KiChjang
KiChjang deleted the update-fetch branch August 19, 2017 01:48
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.

5 participants