Add isNil check to custom Content-Length. (#13867) [backport:1.2]

Related to #13866.
This commit is contained in:
supakeen 2020-04-05 09:02:30 +02:00 • committed by GitHub
commit 09ca19208f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -99,8 +99,9 @@ proc respond*(req: Request, code: HttpCode, content: string,
if headers != nil:
msg.addHeaders(headers)
if not headers.hasKey("Content-Length"):
# If the headers did not contain a Content-Length use our own
if headers.isNil() or not headers.hasKey("Content-Length"):
msg.add("Content-Length: ")
# this particular way saves allocations:
msg.addInt content.len