servo: Merge #10154 - Fix #10147: Correctly handle flag local_urls_only (from stjepang:fix-local-urls-only-10147); r=KiChjang

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.

Fixes #10147.
Test with: `./mach test-unit -p net fetch::test_fetch_with_local_urls_only`

Source-Repo: https://github.com/servo/servo
Source-Revision: 38e8c923b519f488cd0614ff9409997998418cc7
This commit is contained in:
Stjepan Glavina 2016-03-25 12:13:48 +05:01
Родитель da57dda89c
Коммит fdd7bf05a2
3 изменённых файлов: 36 добавлений и 4 удалений

Просмотреть файл

@ -112,9 +112,9 @@ fn main_fetch(request: Rc<Request>, cors_flag: bool, recursive_flag: bool) -> Re
// Step 2
if request.local_urls_only {
match &*request.current_url().scheme {
"about" | "blob" | "data" | "filesystem" => response = Some(Response::network_error()),
_ => { }
};
"about" | "blob" | "data" | "filesystem" => (), // Ok, the URL is local.
_ => response = Some(Response::network_error())
}
}
// Step 3

Просмотреть файл

@ -152,7 +152,7 @@ impl Request {
pub fn new(url: Url,
origin: Option<Origin>,
is_service_worker_global_scope: bool) -> Request {
Request {
Request {
method: RefCell::new(Method::Get),
local_urls_only: false,
sandboxed_storage_area_urls: false,

Просмотреть файл

@ -282,6 +282,38 @@ 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.local_urls_only = true;
let wrapped_request = Rc::new(request);
fetch(wrapped_request)
};
let local_url = Url::parse("about:blank").unwrap();
let local_response = do_fetch(local_url);
let server_response = do_fetch(server_url);
let _ = server.close();
assert!(!local_response.is_network_error());
assert!(server_response.is_network_error());
}
fn test_fetch_redirect_count(message: &'static [u8], redirect_cap: u32) -> Response {
let handler = move |request: HyperRequest, mut response: HyperResponse| {