diff options
Diffstat (limited to 'ext/fetch/lib.rs')
-rw-r--r-- | ext/fetch/lib.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index a3daff040..48f6a0294 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -237,11 +237,11 @@ pub fn op_fetch<FP>( where FP: FetchPermissions + 'static, { - let client = if let Some(rid) = client_rid { + let (client, allow_host) = if let Some(rid) = client_rid { let r = state.resource_table.get::<HttpClientResource>(rid)?; - r.client.clone() + (r.client.clone(), r.allow_host) } else { - get_or_create_client_from_state(state)? + (get_or_create_client_from_state(state)?, false) }; let method = Method::from_bytes(&method)?; @@ -334,7 +334,7 @@ where let v = HeaderValue::from_bytes(&value) .map_err(|err| type_error(err.to_string()))?; - if !matches!(name, HOST | CONTENT_LENGTH) { + if (name != HOST || allow_host) && name != CONTENT_LENGTH { header_map.append(name, v); } } @@ -761,6 +761,7 @@ impl Resource for FetchResponseResource { pub struct HttpClientResource { pub client: Client, + pub allow_host: bool, } impl Resource for HttpClientResource { @@ -770,8 +771,8 @@ impl Resource for HttpClientResource { } impl HttpClientResource { - fn new(client: Client) -> Self { - Self { client } + fn new(client: Client, allow_host: bool) -> Self { + Self { client, allow_host } } } @@ -795,6 +796,8 @@ pub struct CreateHttpClientArgs { http1: bool, #[serde(default = "default_true")] http2: bool, + #[serde(default)] + allow_host: bool, } fn default_true() -> bool { @@ -860,7 +863,9 @@ where }, )?; - let rid = state.resource_table.add(HttpClientResource::new(client)); + let rid = state + .resource_table + .add(HttpClientResource::new(client, args.allow_host)); Ok(rid) } |