Skip to content

Commit

Permalink
Fix fetching about:blank
Browse files Browse the repository at this point in the history
When fetching about:blank, response body should be the empty byte
sequence.
Spec: https://fetch.spec.whatwg.org/#concept-basic-fetch

Before this change, response body would be set to `ResponseBody::Empty`,
and then fetching would result in an infinite loop at step 19 in fn
`main_fetch` (methods.rs).
  • Loading branch information
Stjepan Glavina committed Mar 24, 2016
1 parent ef8d36d commit bcd813d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/net/fetch/methods.rs
Expand Up @@ -294,6 +294,7 @@ fn basic_fetch(request: Rc<Request>) -> Response {
response.headers.set(ContentType(Mime(
TopLevel::Text, SubLevel::Html,
vec![(Attr::Charset, Value::Utf8)])));
*response.body.lock().unwrap() = ResponseBody::Done(vec![]);
response
},
_ => Response::network_error()
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/net/fetch.rs
Expand Up @@ -94,6 +94,20 @@ fn test_fetch_response_body_matches_const_message() {
};
}

#[test]
fn test_fetch_aboutblank() {

let url = Url::parse("about:blank").unwrap();
let origin = Origin::Origin(url.origin());
let mut request = Request::new(url, Some(origin), false);
request.referer = Referer::NoReferer;
let wrapped_request = Rc::new(request);

let fetch_response = fetch(wrapped_request);
assert!(!fetch_response.is_network_error());
assert!(*fetch_response.body.lock().unwrap() == ResponseBody::Done(vec![]));
}

#[test]
fn test_fetch_response_is_basic_filtered() {

Expand Down

0 comments on commit bcd813d

Please sign in to comment.