From cd21cff29942f24ba7d38287186cce64d0e84e56 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 18 Aug 2022 17:35:02 +0530 Subject: feat(ext/flash): An optimized http/1.1 server (#15405) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartek IwaƄczuk Co-authored-by: Ben Noordhuis Co-authored-by: crowlkats Co-authored-by: Ryan Dahl --- ext/fetch/23_response.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'ext/fetch/23_response.js') 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]); + } } } } -- cgit v1.2.3