From 9e6cd91014ac4a0d34556b0d09cbe25e4e0930c6 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 20 Apr 2021 14:47:22 +0200 Subject: chore: align fetch to spec (#10203) This commit aligns the `fetch` API and the `Request` / `Response` classes belonging to it to the spec. This commit enables all the relevant `fetch` WPT tests. Spec compliance is now at around 90%. Performance is essentially identical now (within 1% of 1.9.0). --- op_crates/fetch/lib.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'op_crates/fetch/lib.rs') diff --git a/op_crates/fetch/lib.rs b/op_crates/fetch/lib.rs index 030f8a809..41fb153e0 100644 --- a/op_crates/fetch/lib.rs +++ b/op_crates/fetch/lib.rs @@ -70,13 +70,29 @@ pub fn init(isolate: &mut JsRuntime) { "deno:op_crates/fetch/21_formdata.js", include_str!("21_formdata.js"), ), + ( + "deno:op_crates/fetch/22_body.js", + include_str!("22_body.js"), + ), + ( + "deno:op_crates/fetch/22_http_client.js", + include_str!("22_http_client.js"), + ), + ( + "deno:op_crates/fetch/23_request.js", + include_str!("23_request.js"), + ), + ( + "deno:op_crates/fetch/23_response.js", + include_str!("23_response.js"), + ), ( "deno:op_crates/fetch/26_fetch.js", include_str!("26_fetch.js"), ), ]; for (url, source_code) in files { - isolate.execute(url, source_code).unwrap(); + isolate.execute(url, source_code).expect(url); } } @@ -110,9 +126,8 @@ pub fn get_declaration() -> PathBuf { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] pub struct FetchArgs { - method: Option, + method: String, url: String, - base_url: Option, headers: Vec<(String, String)>, client_rid: Option, has_body: bool, @@ -144,18 +159,8 @@ where client.clone() }; - let method = match args.method { - Some(method_str) => Method::from_bytes(method_str.as_bytes())?, - None => Method::GET, - }; - - 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)?; + let method = Method::from_bytes(args.method.as_bytes())?; + let url = Url::parse(&args.url)?; // Check scheme before asking for net permission let scheme = url.scheme(); -- cgit v1.2.3