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

Fix logic for cors cache match #10867

Merged
merged 2 commits into from Apr 28, 2016
Merged

Fix logic for cors cache match #10867

merged 2 commits into from Apr 28, 2016

Conversation

@dlrobertson
Copy link
Contributor

dlrobertson commented Apr 27, 2016

The current logic for a cors cache match does not consider "credentials is false and request's credentials mode is not "include" or credentials is true."

I could have missed something, but CacheRequestDetails::credentials is set to true if credentials mode is "include", and false otherwise. So (!cors_cache.credentials && !cors_req.credentials) || cors_cache.credentials would be directly following the spec, but unless I'm mistaken cors_cache.credentials || !cors_req.credentials is logically the same.

Fixes: #10525


This change is Reviewable

@highfive
Copy link

highfive commented Apr 27, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/net/fetch/cors_cache.rs
@highfive
Copy link

highfive commented Apr 27, 2016

warning Warning warning

  • These commits modify net code, but no tests are modified. Please consider adding a test!
@@ -112,7 +112,7 @@ pub struct BasicCORSCache(Vec<CORSCacheEntry>);
fn match_headers(cors_cache: &CORSCacheEntry, cors_req: &CacheRequestDetails) -> bool {
cors_cache.origin == cors_req.origin &&
cors_cache.url == cors_req.destination &&

This comment has been minimized.

@KiChjang

KiChjang Apr 27, 2016

Member

Hmm... spec says "url is request's current url", so I'd expect to see something like cors_cache.url == cors_req.current_url() instead.

This comment has been minimized.

@dlrobertson

dlrobertson Apr 27, 2016

Author Contributor

Great point. Didn't think to question that since the Issue was focused on the later logic. After looking at CacheRequestDetails, destination is the only Url member. Is destination used as the "current URL" in here?

This comment has been minimized.

@KiChjang

KiChjang Apr 27, 2016

Member

Wait, sorry. I didn't notice that cors_req is an instance of CacheRequestDetails, so the code as it is is fine.

This comment has been minimized.

@dlrobertson

dlrobertson Apr 27, 2016

Author Contributor

No worries. Thanks for taking a peek at the code!

@KiChjang
Copy link
Member

KiChjang commented Apr 27, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Apr 27, 2016

📌 Commit c01f8af has been approved by KiChjang

@jdm
Copy link
Member

jdm commented Apr 27, 2016

@bors-servo: r-
Before we merge these changes, I'd like to either have a test for it or be explicit that we can't write one.

@jdm jdm added S-needs-tests and removed S-awaiting-merge labels Apr 27, 2016
@dlrobertson
Copy link
Contributor Author

dlrobertson commented Apr 27, 2016

No problem. Where are the cors tests?

@jdm
Copy link
Member

jdm commented Apr 27, 2016

For the fetch code, it's tests/unit/net/fetch.rs. That code isn't hooked up to real WPT tests yet.

@dlrobertson dlrobertson force-pushed the dlrobertson:sandbox branch from c01f8af to bc32e8e Apr 27, 2016
@dlrobertson
Copy link
Contributor Author

dlrobertson commented Apr 27, 2016

Review status: 0 of 4 files reviewed at latest revision, 2 unresolved discussions.


components/net/fetch/cors_cache.rs, line 153 [r2] (raw file):
> will find the entries that need to be dropped. < to find the ones to keep.


Comments from Reviewable

@@ -40,6 +40,10 @@ pub fn fetch_async(request: Request, listener: Box<AsyncFetchListener + Send>) {

/// [Fetch](https://fetch.spec.whatwg.org#concept-fetch)
pub fn fetch(request: Rc<Request>) -> Response {
fetch_with_cors_cache(request, &mut BasicCORSCache::new())

This comment has been minimized.

@KiChjang

KiChjang Apr 27, 2016

Member

This is not behaviour documented in the fetch spec. @jdm does this look ok?

This comment has been minimized.

This comment has been minimized.

@jdm

jdm Apr 27, 2016

Member

👍

fetch_with_cors_cache(request, &mut BasicCORSCache::new())
}

pub fn fetch_with_cors_cache<C: CORSCache>(request: Rc<Request>, cache: &mut C) -> Response {

This comment has been minimized.

@KiChjang

KiChjang Apr 27, 2016

Member

I'm not sure why cache: &mut CORSCache wouldn't work here.

This comment has been minimized.

@dlrobertson

dlrobertson Apr 27, 2016

Author Contributor

CORSCache is a trait, so you'll get the following error.

error: the trait bound `<trait>: std::marker::Sized` is not satisfied

I couldn't think of another way around it

The current logic for a cors cache match does not consider "credentials
is false and request's credentials mode is not "include" or credentials
is true."
@dlrobertson dlrobertson force-pushed the dlrobertson:sandbox branch from bc32e8e to 9d1b9da Apr 27, 2016
Remove the CORSCache trait, CORSCacheSender, CORSCacheThreadMsg, and
CORSCacheThread. Rename BasicCORSCache to CORSCache and keep its old
implementation of CORSCache.
@dlrobertson dlrobertson force-pushed the dlrobertson:sandbox branch from 9d1b9da to 483f07c Apr 27, 2016
@@ -74,51 +73,20 @@ pub struct CacheRequestDetails {
pub credentials: bool

This comment has been minimized.

@KiChjang

KiChjang Apr 28, 2016

Member

I'm wondering whether we even need this CacheRequestDetails struct at all... it feels like we can just do away this altogether and use Request instead. I think I'll file a follow-up issue to remove this.

This comment has been minimized.

@KiChjang
Copy link
Member

KiChjang commented Apr 28, 2016

@bors-servo r+

Thanks!

@bors-servo
Copy link
Contributor

bors-servo commented Apr 28, 2016

📌 Commit 483f07c has been approved by KiChjang

1 similar comment
@bors-servo
Copy link
Contributor

bors-servo commented Apr 28, 2016

📌 Commit 483f07c has been approved by KiChjang

@bors-servo
Copy link
Contributor

bors-servo commented Apr 28, 2016

Testing commit 483f07c with merge 3d38a60...

bors-servo added a commit that referenced this pull request Apr 28, 2016
Fix logic for cors cache match

The current logic for a cors cache match does not consider "credentials is false and request's credentials mode is not "include" or credentials is true."

I could have missed something, but `CacheRequestDetails::credentials` is set to true if credentials mode is "include", and false otherwise. So `(!cors_cache.credentials && !cors_req.credentials) || cors_cache.credentials` would be directly following the spec, but unless I'm mistaken `cors_cache.credentials || !cors_req.credentials` is logically the same.

Fixes: #10525

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10867)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Apr 28, 2016

@bors-servo bors-servo merged commit 483f07c into servo:master Apr 28, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.