Skip to content

Commit

Permalink
Add isNil check to custom Content-Length. (#13867) [backport:1.2]
Browse files Browse the repository at this point in the history
Related to #13866.

(cherry picked from commit 09ca192)
  • Loading branch information
supakeen authored and narimiran committed Apr 14, 2020
1 parent 7e83adf commit c4dfdb7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/pure/asynchttpserver.nim
Expand Up @@ -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
Expand Down

0 comments on commit c4dfdb7

Please sign in to comment.