diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2018-12-09 18:44:13 +0100 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-09 15:24:54 -0500 |
| commit | 2b360c60a5b7bfd9b1ac3c1afc8f38ffb9209d32 (patch) | |
| tree | aa0cae51df609fc01e7babe63ae9fca8dcfc4c38 | |
| parent | 2516281306a5d49fc987a18461a4982625c890f8 (diff) | |
set content-length for bodyless response
Original: https://github.com/denoland/deno_std/commit/0e82a4249ead38be9ff0e35b2df97eb6dc8ca139
| -rw-r--r-- | http.ts | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -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()); } } |
