diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-08-18 17:35:02 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-18 17:35:02 +0530 |
commit | cd21cff29942f24ba7d38287186cce64d0e84e56 (patch) | |
tree | e663eff884526ee762ae9141a3cf5a0f6967a84e /ext/fetch/23_response.js | |
parent | 0b0843e4a54d7c1ddf293ac1ccee2479b69a5ba9 (diff) |
feat(ext/flash): An optimized http/1.1 server (#15405)
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
Co-authored-by: crowlkats <crowlkats@toaxl.com>
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
Diffstat (limited to 'ext/fetch/23_response.js')
-rw-r--r-- | ext/fetch/23_response.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/ext/fetch/23_response.js b/ext/fetch/23_response.js index 226a751bd..3c19f963a 100644 --- a/ext/fetch/23_response.js +++ b/ext/fetch/23_response.js @@ -15,6 +15,9 @@ const { isProxy } = Deno.core; const webidl = window.__bootstrap.webidl; const consoleInternal = window.__bootstrap.console; + const { + byteLowerCase, + } = window.__bootstrap.infra; const { HTTP_TAB_OR_SPACE, regexMatcher, serializeJSValueToJSONString } = window.__bootstrap.infra; const { extractBody, mixinBody } = window.__bootstrap.fetchBody; @@ -185,7 +188,6 @@ // 4. response[_response].statusMessage = init.statusText; - // 5. /** @type {__bootstrap.headers.Headers} */ const headers = response[_headers]; @@ -200,10 +202,22 @@ "Response with null body status cannot have body", ); } + const { body, contentType } = bodyWithType; response[_response].body = body; - if (contentType !== null && !headers.has("content-type")) { - headers.append("Content-Type", contentType); + + if (contentType !== null) { + let hasContentType = false; + const list = headerListFromHeaders(headers); + for (let i = 0; i < list.length; i++) { + if (byteLowerCase(list[i][0]) === "content-type") { + hasContentType = true; + break; + } + } + if (!hasContentType) { + ArrayPrototypePush(list, ["Content-Type", contentType]); + } } } } |