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

Fixes #14787: Set Origin header in http_network_or_cache_fetch #14811

Closed
wants to merge 1 commit into from

Conversation

rabisg
Copy link
Contributor

@rabisg rabisg commented Jan 1, 2017

Sets Origin header on request with CORS flag set or on requests other
than those with GET/HEAD methods

There are 2 TODOs marked in the current implementation:

  • Set Origin to be Client origin when client object is implemented in Request
  • Set Origin to null (OpaqueOrigin) when hyper supports it (This seems to be missing from the current implementation in hyper)

  • There are tests for these changes

This change is Reviewable

@highfive
Copy link

highfive commented Jan 1, 2017

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @wafflespeanut (or someone else) soon.

@highfive
Copy link

highfive commented Jan 1, 2017

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 Jan 1, 2017
@rabisg rabisg force-pushed the set-origin-header branch 2 times, most recently from 75f4077 to 234fd2d Compare January 2, 2017 18:34
@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #14784) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Jan 2, 2017
@KiChjang
Copy link
Contributor

KiChjang commented Jan 3, 2017

Sorry, but could you remove your merge commit and rebase against the master branch instead? We don't accept PRs that contain merge commits.

@rabisg
Copy link
Contributor Author

rabisg commented Jan 3, 2017

Sorry was trying Github resolve conflict for the first time. Didn't realise it created a merge commit. Fixed that.

Sets Origin header on request with CORS flag set or on requests other
than those with GET/HEAD methods
@jdm jdm removed the S-needs-rebase There are merge conflict errors. label Jan 3, 2017
@jdm
Copy link
Member

jdm commented Jan 12, 2017

@wafflespeanut Review ping!

@wafflespeanut
Copy link
Contributor

I don't even recall seeing this. Sorry, will review it in a bit :)

Copy link
Contributor

@wafflespeanut wafflespeanut left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in review. Just a few comments 😄

// TODO update this when https://github.com/hyperium/hyper/pull/691 is finished
// http_request.headers.borrow_mut().set_raw("origin", origin);
// Step 7
if http_request.omit_origin_header.get() == false {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This should be,

if !http_request.omit_origin_header.get() {

(*http_request.method.borrow() != Method::Get && *http_request.method.borrow() != Method::Head) {
// TODO update this when https://github.com/hyperium/hyper/pull/691 is finished
// http_request.headers.borrow_mut().set_raw("origin", origin);
// Step 7
Copy link
Contributor

Choose a reason for hiding this comment

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

This is step 9.

if cors_flag || (*method != Method::Get && *method != Method::Head) {
match *http_request.origin.borrow() {
Origin::Origin(ref url_origin) =>
match try_url_origin_to_hyper_origin(url_origin.clone()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have to clone if we don't move anything from it. We can just pass the reference, deref it, and clone stuff only when needed. Also, this could be rewritten with if let as,

if let Some(hyper_origin) = try_url_origin_to_hyper_origin(url_origin) {
    //
}

// Step 7
if http_request.omit_origin_header.get() == false {
let method = http_request.method.borrow();
if cors_flag || (*method != Method::Get && *method != Method::Head) {
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the spec, the request's origin will be changed to "client" during fetching. We should have a debug_assert!(*http_request.origin.borrow() != Origin::Client) and go with if let here.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jan 19, 2017
@wafflespeanut
Copy link
Contributor

@rabisg Any plans to finish this off?

@jdm
Copy link
Member

jdm commented Feb 3, 2017

Closing due to lack of activity.

@jdm jdm closed this Feb 3, 2017
bors-servo pushed a commit that referenced this pull request Feb 15, 2017
Fixes #14787 building on #14811:  Set Origin header in http_network_or_cache_fetch

Incorporates review feedback from #14811

I noticed that the "steps" in the comments don't necessarily correspond to the steps in the current fetch standard.  This adds step 11 in the spec, but the steps commented in the implementation look wrong.

---

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #14787.
- [x] There are tests for these changes

<!-- 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/15547)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this pull request Feb 16, 2017
Fixes #14787 building on #14811:  Set Origin header in http_network_or_cache_fetch

Incorporates review feedback from #14811

I noticed that the "steps" in the comments don't necessarily correspond to the steps in the current fetch standard.  This adds step 11 in the spec, but the steps commented in the implementation look wrong.

---

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #14787.
- [x] There are tests for these changes

<!-- 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/15547)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this pull request Feb 17, 2017
Fixes #14787 building on #14811:  Set Origin header in http_network_or_cache_fetch

Incorporates review feedback from #14811

I noticed that the "steps" in the comments don't necessarily correspond to the steps in the current fetch standard.  This adds step 11 in the spec, but the steps commented in the implementation look wrong.

---

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #14787.
- [x] There are tests for these changes

<!-- 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/15547)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this pull request Feb 18, 2017
Fixes #14787 building on #14811:  Set Origin header in http_network_or_cache_fetch

Incorporates review feedback from #14811

I noticed that the "steps" in the comments don't necessarily correspond to the steps in the current fetch standard.  This adds step 11 in the spec, but the steps commented in the implementation look wrong.

---

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #14787.
- [x] There are tests for these changes

<!-- 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/15547)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this pull request Feb 20, 2017
Fixes #14787 building on #14811:  Set Origin header in http_network_or_cache_fetch

Incorporates review feedback from #14811

I noticed that the "steps" in the comments don't necessarily correspond to the steps in the current fetch standard.  This adds step 11 in the spec, but the steps commented in the implementation look wrong.

---

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #14787.
- [x] There are tests for these changes

<!-- 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/15547)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this pull request Feb 21, 2017
Fixes #14787 building on #14811:  Set Origin header in http_network_or_cache_fetch

Incorporates review feedback from #14811

I noticed that the "steps" in the comments don't necessarily correspond to the steps in the current fetch standard.  This adds step 11 in the spec, but the steps commented in the implementation look wrong.

---

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #14787.
- [x] There are tests for these changes

<!-- 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/15547)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this pull request Feb 24, 2017
Fixes #14787 building on #14811:  Set Origin header in http_network_or_cache_fetch

Incorporates review feedback from #14811

I noticed that the "steps" in the comments don't necessarily correspond to the steps in the current fetch standard.  This adds step 11 in the spec, but the steps commented in the implementation look wrong.

---

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #14787.
- [x] There are tests for these changes

<!-- 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/15547)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this pull request Mar 10, 2017
Allow for redirects after a CORS-preflight

~Continue the work done in #14811 and #15547~. And applies the Fetch [spec change](whatwg/fetch@0d9a4db) about [allowing redirects after CORS preflights](whatwg/fetch#204).

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix ~#14787 and~ #14519
- [X] There are tests for these changes. Several WPTs go from FAIL to SUCCESS. The new expected FAILs for the cors/redirect-preflight.htm tests are caused by the spec change done [here](whatwg/fetch@0d9a4db), as suggested in the associated [issue](#14519 (comment)).

<!-- 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/15889)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this pull request Mar 10, 2017
Allow for redirects after a CORS-preflight

~Continue the work done in #14811 and #15547~. And applies the Fetch [spec change](whatwg/fetch@0d9a4db) about [allowing redirects after CORS preflights](whatwg/fetch#204).

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix ~#14787 and~ #14519
- [X] There are tests for these changes. Several WPTs go from FAIL to SUCCESS. The new expected FAILs for the cors/redirect-preflight.htm tests are caused by the spec change done [here](whatwg/fetch@0d9a4db), as suggested in the associated [issue](#14519 (comment)).

<!-- 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/15889)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-needs-code-changes Changes have not yet been made that were requested by a reviewer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set origin header in http_network_or_cache_fetch
6 participants