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
parent 813ed358bf
commit 09ca19208f

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