mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #10154 - stjepang:fix-local-urls-only-10147, r=KiChjang
Fix #10147: 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. Fixes #10147. Test with: `./mach test-unit -p net fetch::test_fetch_with_local_urls_only` <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10154) <!-- Reviewable:end -->
This commit is contained in:
commit
38e8c923b5
3 changed files with 36 additions and 4 deletions
|
@ -112,9 +112,9 @@ fn main_fetch(request: Rc<Request>, cors_flag: bool, recursive_flag: bool) -> Re
|
||||||
// Step 2
|
// Step 2
|
||||||
if request.local_urls_only {
|
if request.local_urls_only {
|
||||||
match &*request.current_url().scheme {
|
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
|
// Step 3
|
||||||
|
|
|
@ -152,7 +152,7 @@ impl Request {
|
||||||
pub fn new(url: Url,
|
pub fn new(url: Url,
|
||||||
origin: Option<Origin>,
|
origin: Option<Origin>,
|
||||||
is_service_worker_global_scope: bool) -> Request {
|
is_service_worker_global_scope: bool) -> Request {
|
||||||
Request {
|
Request {
|
||||||
method: RefCell::new(Method::Get),
|
method: RefCell::new(Method::Get),
|
||||||
local_urls_only: false,
|
local_urls_only: false,
|
||||||
sandboxed_storage_area_urls: 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 {
|
fn test_fetch_redirect_count(message: &'static [u8], redirect_cap: u32) -> Response {
|
||||||
|
|
||||||
let handler = move |request: HyperRequest, mut response: HyperResponse| {
|
let handler = move |request: HyperRequest, mut response: HyperResponse| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue