From 2b360c60a5b7bfd9b1ac3c1afc8f38ffb9209d32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 9 Dec 2018 18:44:13 +0100 Subject: set content-length for bodyless response Original: https://github.com/denoland/deno_std/commit/0e82a4249ead38be9ff0e35b2df97eb6dc8ca139 --- http.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'http.ts') diff --git a/http.ts b/http.ts index 2dab9e1e5..e709dd4a3 100644 --- a/http.ts +++ b/http.ts @@ -89,13 +89,12 @@ interface Response { } function setContentLength(r: Response): void { - if (r.body) { - if (!r.headers) { - r.headers = new Headers(); - } - if (!r.headers.has("content-length")) { - r.headers.append("Content-Length", r.body.byteLength.toString()); - } + if (!r.headers) { + r.headers = new Headers(); + } + if (!r.headers.has("content-length")) { + const bodyLength = r.body ? r.body.byteLength : 0 + r.headers.append("Content-Length", bodyLength.toString()); } } -- cgit v1.2.3