From 09ca19208f7c9aa52e71b50cf53cc369612e3fce Mon Sep 17 00:00:00 2001 From: supakeen <39536295+supakeen@users.noreply.github.com> Date: Sun, 5 Apr 2020 09:02:30 +0200 Subject: [PATCH] Add isNil check to custom Content-Length. (#13867) [backport:1.2] Related to #13866. --- lib/pure/asynchttpserver.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/pure/asynchttpserver.nim b/lib/pure/asynchttpserver.nim index a9ea4780fb..7fbbf38ea3 100644 --- a/lib/pure/asynchttpserver.nim +++ b/lib/pure/asynchttpserver.nim @@ -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