Auto merge of #25695 - pshaughn:eventsource, r=nox

Let EventSource fail fast on bad schemes

<!-- Please describe your changes on the following line: -->
EventSource went into an infinite reconnect loop in some cases where tests wanted it to go into a hard error state; this addresses the cases where that happens because the url isn't even http(s) and will thus definitely never result in an event stream.

https://github.com/web-platform-tests/wpt/issues/4311 suggests the tests might just be too picky here; the spec does use the word "may" on relevant behavior.

---
<!-- 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 #25692

<!-- Either: -->
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-02-10 20:01:01 -05:00 committed by GitHub
commit 7b540945cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 30 deletions

View file

@ -32,7 +32,7 @@ use js::conversions::ToJSValConvertible;
use js::jsval::UndefinedValue;
use mime::{self, Mime};
use net_traits::request::{CacheMode, CorsSettings, Destination, RequestBuilder};
use net_traits::{CoreResourceMsg, FetchChannels, FetchMetadata};
use net_traits::{CoreResourceMsg, FetchChannels, FetchMetadata, FilteredMetadata};
use net_traits::{FetchResponseListener, FetchResponseMsg, NetworkError};
use net_traits::{ResourceFetchTiming, ResourceTimingType};
use servo_atoms::Atom;
@ -339,7 +339,12 @@ impl FetchResponseListener for EventSourceContext {
Ok(fm) => {
let meta = match fm {
FetchMetadata::Unfiltered(m) => m,
FetchMetadata::Filtered { unsafe_, .. } => unsafe_,
FetchMetadata::Filtered { unsafe_, filtered } => match filtered {
FilteredMetadata::Opaque | FilteredMetadata::OpaqueRedirect => {
return self.fail_the_connection()
},
_ => unsafe_,
},
};
let mime = match meta.content_type {
None => return self.fail_the_connection(),
@ -352,7 +357,13 @@ impl FetchResponseListener for EventSourceContext {
self.announce_the_connection();
},
Err(_) => {
self.reestablish_the_connection();
// The spec advises failing here if reconnecting would be
// "futile", with no more specific advice; WPT tests
// consider a non-http(s) scheme to be futile.
match self.event_source.root().url.scheme() {
"http" | "https" => self.reestablish_the_connection(),
_ => self.fail_the_connection(),
}
},
}
}

View file

@ -5,13 +5,3 @@
[dedicated worker - EventSource: constructor (act as if there is a network error) (https://example.not/test)]
expected: FAIL
[dedicated worker - EventSource: constructor (act as if there is a network error) (ftp://example.not/)]
expected: FAIL
[dedicated worker - EventSource: constructor (act as if there is a network error) (mailto:whatwg@awesome.example)]
expected: FAIL
[dedicated worker - EventSource: constructor (act as if there is a network error) (javascript:alert('FAIL'))]
expected: FAIL

View file

@ -1,17 +0,0 @@
[eventsource-constructor-non-same-origin.htm]
type: testharness
[EventSource: constructor (act as if there is a network error) (http://example.not/)]
expected: FAIL
[EventSource: constructor (act as if there is a network error) (https://example.not/test)]
expected: FAIL
[EventSource: constructor (act as if there is a network error) (ftp://example.not/)]
expected: FAIL
[EventSource: constructor (act as if there is a network error) (mailto:whatwg@awesome.example)]
expected: FAIL
[EventSource: constructor (act as if there is a network error) (javascript:alert('FAIL'))]
expected: FAIL