diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-09-27 22:36:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-27 22:36:33 +0200 |
commit | 212b7dd6da487c070229b6348ec7907b4fecbcf9 (patch) | |
tree | 3eb743f90e8b293182a830722eb4ff26bec72039 /ext/fetch/lib.rs | |
parent | a344368603063bcb281e743f3810ca1e4e46e85d (diff) |
feat: Add requesting API name to permission prompt (#15936)
Co-authored-by: Leo Kettmeir <crowlkats@toaxl.com>
Diffstat (limited to 'ext/fetch/lib.rs')
-rw-r--r-- | ext/fetch/lib.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index 3988acf9e..a7daaa63a 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -167,8 +167,12 @@ impl FetchHandler for DefaultFileFetchHandler { } pub trait FetchPermissions { - fn check_net_url(&mut self, _url: &Url) -> Result<(), AnyError>; - fn check_read(&mut self, _p: &Path) -> Result<(), AnyError>; + fn check_net_url( + &mut self, + _url: &Url, + api_name: &str, + ) -> Result<(), AnyError>; + fn check_read(&mut self, _p: &Path, api_name: &str) -> Result<(), AnyError>; } pub fn get_declaration() -> PathBuf { @@ -215,7 +219,7 @@ where type_error("NetworkError when attempting to fetch resource.") })?; let permissions = state.borrow_mut::<FP>(); - permissions.check_read(&path)?; + permissions.check_read(&path, "fetch()")?; if method != Method::GET { return Err(type_error(format!( @@ -240,7 +244,7 @@ where } "http" | "https" => { let permissions = state.borrow_mut::<FP>(); - permissions.check_net_url(&url)?; + permissions.check_net_url(&url, "fetch()")?; let mut request = client.request(method.clone(), url); @@ -535,7 +539,7 @@ where if let Some(proxy) = args.proxy.clone() { let permissions = state.borrow_mut::<FP>(); let url = Url::parse(&proxy.url)?; - permissions.check_net_url(&url)?; + permissions.check_net_url(&url, "Deno.createHttpClient()")?; } let client_cert_chain_and_key = { |