Correctly handle flag local_urls_only

In function Request::fetch_main, flag local_urls_only (if set)
should allow fetching local urls only. Before this change, the flag had
the inverse behaviour.
This commit is contained in:
Stjepan Glavina 2016-03-23 18:01:43 +01:00
parent ef8d36d208
commit 6576fde29b
3 changed files with 43 additions and 6 deletions

View file

@ -268,6 +268,35 @@ fn test_fetch_response_is_opaque_redirect_filtered() {
}
}
#[test]
fn test_fetch_with_local_urls_only() {
// If flag `local_urls_only` is set, fetching a non-local URL must result in network error.
static MESSAGE: &'static [u8] = b"";
let handler = move |_: HyperRequest, response: HyperResponse| {
response.send(MESSAGE).unwrap();
};
let (mut server, server_url) = make_server(handler);
let do_fetch = |url: Url| {
let origin = Origin::Origin(url.origin());
let mut request = Request::new(url, Some(origin), false);
request.referer = Referer::NoReferer;
// Set the flag.
request.set_local_urls_only(true);
let wrapped_request = Rc::new(request);
fetch(wrapped_request)
};
let local_url = Url::parse("about:config").unwrap();
assert!(do_fetch(local_url).is_network_error());
assert!(!do_fetch(server_url).is_network_error());
let _ = server.close();
}
fn test_fetch_redirect_count(message: &'static [u8], redirect_cap: u32) -> Response {
let handler = move |request: HyperRequest, mut response: HyperResponse| {