fix asynchttpserver content-length header (#13846)

This commit is contained in:
flywind 2020-04-03 15:05:43 +08:00 • committed by GitHub
commit 6b9ffc7fad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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