Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
- Remove fn `url_is_local`
- Remove fn `set_local_urls_only`
- Fix `test_fetch_with_local_urls_only`
  • Loading branch information
Stjepan Glavina committed Mar 24, 2016
1 parent 6576fde commit 3ec4515
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
14 changes: 5 additions & 9 deletions components/net/fetch/methods.rs
Expand Up @@ -110,8 +110,11 @@ fn main_fetch(request: Rc<Request>, cors_flag: bool, recursive_flag: bool) -> Re
let mut response = None;

// Step 2
if request.local_urls_only && !url_is_local(&request.current_url()) {
response = Some(Response::network_error());
if request.local_urls_only {
match &*request.current_url().scheme {
"about" | "blob" | "data" | "filesystem" => (), // Ok, the URL is local.
_ => response = Some(Response::network_error())
}
}

// Step 3
Expand Down Expand Up @@ -1044,13 +1047,6 @@ fn includes_credentials(url: &Url) -> bool {
false
}

fn url_is_local(url: &Url) -> bool {
match &*url.scheme {
"about" | "blob" | "data" | "filesystem" => true,
_ => false
}
}

fn response_needs_revalidation(_response: &Response) -> bool {
// TODO this function
false
Expand Down
4 changes: 0 additions & 4 deletions components/net_traits/request.rs
Expand Up @@ -257,8 +257,4 @@ impl Request {
_ => false
}
}

pub fn set_local_urls_only(&mut self, local_urls_only: bool) {
self.local_urls_only = local_urls_only;
}
}
11 changes: 7 additions & 4 deletions tests/unit/net/fetch.rs
Expand Up @@ -284,17 +284,20 @@ fn test_fetch_with_local_urls_only() {
request.referer = Referer::NoReferer;

// Set the flag.
request.set_local_urls_only(true);
request.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 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 {
Expand Down

0 comments on commit 3ec4515

Please sign in to comment.