diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2021-01-07 18:06:08 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-07 19:06:08 +0100 |
commit | e61e81eb57351782862aa50775ce4348f10b1856 (patch) | |
tree | 6099aa60857f586774a195034f18ac1fb10ca519 /op_crates/fetch/lib.rs | |
parent | c347dfcd565c3a396ae84dff46e7374851913462 (diff) |
feat: add --location=<href> and globalThis.location (#7369)
Diffstat (limited to 'op_crates/fetch/lib.rs')
-rw-r--r-- | op_crates/fetch/lib.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/op_crates/fetch/lib.rs b/op_crates/fetch/lib.rs index 91e44f75c..c2e458d89 100644 --- a/op_crates/fetch/lib.rs +++ b/op_crates/fetch/lib.rs @@ -100,12 +100,12 @@ where struct FetchArgs { method: Option<String>, url: String, + base_url: Option<String>, headers: Vec<(String, String)>, client_rid: Option<u32>, } let args: FetchArgs = serde_json::from_value(args)?; - let url = args.url; let client = if let Some(rid) = args.client_rid { let state_ = state.borrow(); @@ -125,10 +125,16 @@ where None => Method::GET, }; - let url_ = Url::parse(&url)?; + let base_url = match args.base_url { + Some(base_url) => Some(Url::parse(&base_url)?), + _ => None, + }; + let url = Url::options() + .base_url(base_url.as_ref()) + .parse(&args.url)?; // Check scheme before asking for net permission - let scheme = url_.scheme(); + let scheme = url.scheme(); if scheme != "http" && scheme != "https" { return Err(type_error(format!("scheme '{}' not supported", scheme))); } @@ -136,10 +142,10 @@ where { let state_ = state.borrow(); let permissions = state_.borrow::<FP>(); - permissions.check_net_url(&url_)?; + permissions.check_net_url(&url)?; } - let mut request = client.request(method, url_); + let mut request = client.request(method, url); match data.len() { 0 => {} |