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

Xhr data #9972

Merged
merged 7 commits into from
Apr 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions components/net_traits/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,18 @@ impl Metadata {

/// Extract the parts of a Mime that we care about.
pub fn set_content_type(&mut self, content_type: Option<&Mime>) {
match self.headers {
None => self.headers = Some(Headers::new()),
Some(_) => (),
}

match content_type {
None => (),
Some(mime) => {
if let Some(headers) = self.headers.as_mut() {
headers.set(ContentType(mime.clone()));
}

self.content_type = Some(ContentType(mime.clone()));
let &Mime(_, _, ref parameters) = mime;
for &(ref k, ref v) in parameters {
Expand Down
12 changes: 9 additions & 3 deletions components/script/cors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,21 @@ impl CORSRequest {
destination: Url,
mode: RequestMode,
method: Method,
headers: Headers)
headers: Headers,
same_origin_data_url_flag: bool)
-> Result<Option<CORSRequest>, ()> {
if referer.scheme == destination.scheme && referer.host() == destination.host() &&
referer.port() == destination.port() {
return Ok(None); // Not cross-origin, proceed with a normal fetch
}
match &*destination.scheme {
// TODO: If the request's same origin data url flag is set (which isn't the case for XHR)
// we can fetch a data URL normally. about:blank can also be fetched by XHR
// As per (https://fetch.spec.whatwg.org/#main-fetch 5.1.9), about URLs can be fetched
// the same as a basic request.
"about" if destination.path() == Some(&["blank".to_owned()]) => Ok(None),
// As per (https://fetch.spec.whatwg.org/#main-fetch 5.1.9), data URLs can be fetched
// the same as a basic request if the request's method is GET and the
// same-origin data-URL flag is set.
"data" if same_origin_data_url_flag && method == Method::Get => Ok(None),
"http" | "https" => {
let mut req = CORSRequest::new(referer, destination, mode, method, headers);
req.preflight_flag = !is_simple_method(&req.method) ||
Expand Down
6 changes: 4 additions & 2 deletions components/script/dom/xmlhttprequest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
load_data.url.clone(),
mode,
load_data.method.clone(),
combined_headers);
combined_headers,
true);
match cors_request {
Ok(None) => {
let mut buf = String::new();
Expand Down Expand Up @@ -1301,7 +1302,8 @@ impl XMLHttpRequest {
global: GlobalRef) -> ErrorResult {
let cors_request = match cors_request {
Err(_) => {
// Happens in case of cross-origin non-http URIs
// Happens in case of unsupported cross-origin URI schemes.
// Supported schemes are http, https, data, and about.
self.process_partial_response(XHRProgress::Errored(
self.generation_id.get(), Error::Network));
return Err(Error::Network);
Expand Down
11 changes: 0 additions & 11 deletions tests/wpt/metadata/XMLHttpRequest/data-uri.htm.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
[data-uri.htm]
type: testharness
[XHR method GET with charset text/plain]
expected: FAIL

[XHR method GET with charset text/plain (base64)]
expected: FAIL

[XHR method GET with charset text/html]
expected: FAIL

[XHR method GET with charset image/png]
expected: FAIL

[XHR method GET with charset text/html;charset=UTF-8]
expected: FAIL
Expand Down