improvements for httpcore (#12228)

* improvements for httpcore
* further improvements, now stable API but needs extensions later on
This commit is contained in:
Andreas Rumpf 2019-09-23 12:38:35 +02:00 • committed by GitHub
commit b865c2a54b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 44 deletions

View file

@ -78,7 +78,7 @@ proc sendHeaders*(req: Request, headers: HttpHeaders): Future[void] =
return req.client.send(msg)
proc respond*(req: Request, code: HttpCode, content: string,
headers: HttpHeaders = nil): Future[void] =
headers = EmptyHttpHeaders): Future[void] =
## Responds to the request with the specified ``HttpCode``, headers and
## content.
##
@ -97,7 +97,7 @@ proc respond*(req: Request, code: HttpCode, content: string,
## await req.respond(Http404, "Not Found")
var msg = "HTTP/1.1 " & $code & "\c\L"
if headers != nil:
if isEmpty(headers):
msg.addHeaders(headers)
msg.add("Content-Length: ")
# this particular way saves allocations: