summaryrefslogtreecommitdiff
path: root/op_crates/fetch/lib.rs
diff options
context:
space:
mode:
authorLuca Casonato <lucacasonato@yahoo.com>2021-04-20 14:47:22 +0200
committerGitHub <noreply@github.com>2021-04-20 14:47:22 +0200
commit9e6cd91014ac4a0d34556b0d09cbe25e4e0930c6 (patch)
tree4523790510a17676c987039feb03f208a258dc16 /op_crates/fetch/lib.rs
parent115197ffb06aad2a3045e8478980ab911b5a5eeb (diff)
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).
Diffstat (limited to 'op_crates/fetch/lib.rs')
-rw-r--r--op_crates/fetch/lib.rs35
1 files changed, 20 insertions, 15 deletions
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
@@ -71,12 +71,28 @@ pub fn init(isolate: &mut JsRuntime) {
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<String>,
+ method: String,
url: String,
- base_url: Option<String>,
headers: Vec<(String, String)>,
client_rid: Option<u32>,
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();