fix asynchttpserver content-length header (#13846)

This commit is contained in:
flywind
2020-04-03 15:05:43 +08:00
committed by GitHub
parent d23371fdd7
commit 6b9ffc7fad

View File

@@ -99,9 +99,12 @@ proc respond*(req: Request, code: HttpCode, content: string,
if headers != nil:
msg.addHeaders(headers)
msg.add("Content-Length: ")
# this particular way saves allocations:
msg.add content.len
if not headers.hasKey("Content-Length"):
msg.add("Content-Length: ")
# this particular way saves allocations:
msg.addInt content.len
msg.add "\c\L\c\L"
msg.add(content)
result = req.client.send(msg)