Skip to content

Commit

Permalink
Fail fast on bad schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
pshaughn committed Feb 10, 2020
1 parent 5f55cd5 commit 7ef644c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 30 deletions.
17 changes: 14 additions & 3 deletions components/script/dom/eventsource.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
}
},
}
}
Expand Down
Expand Up @@ -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

This file was deleted.

0 comments on commit 7ef644c

Please sign in to comment.