Haven't tested this patch but should work.
This commit is contained in:
Dominik Picheta 2015-06-08 23:10:50 +01:00
commit c4009c6182

View file

@ -569,7 +569,7 @@ proc downloadFile*(url: string, outputFilename: string,
fileError("Unable to open file") fileError("Unable to open file")
proc generateHeaders(r: Uri, httpMethod: string, proc generateHeaders(r: Uri, httpMethod: string,
headers: StringTableRef): string = headers: StringTableRef, body: string): string =
# TODO: Use this in the blocking HttpClient once it supports proxies. # TODO: Use this in the blocking HttpClient once it supports proxies.
result = substr(httpMethod, len("http")) result = substr(httpMethod, len("http"))
# TODO: Proxies # TODO: Proxies
@ -582,6 +582,8 @@ proc generateHeaders(r: Uri, httpMethod: string,
add(result, "Host: " & r.hostname & "\c\L") add(result, "Host: " & r.hostname & "\c\L")
add(result, "Connection: Keep-Alive\c\L") add(result, "Connection: Keep-Alive\c\L")
if body.len > 0 and not headers.hasKey("Content-Length"):
add(result, "Content-Length: " & $body.len & "\c\L")
for key, val in headers: for key, val in headers:
add(result, key & ": " & val & "\c\L") add(result, key & ": " & val & "\c\L")
@ -786,7 +788,7 @@ proc request*(client: AsyncHttpClient, url: string, httpMethod: string,
if not client.headers.hasKey("user-agent") and client.userAgent != "": if not client.headers.hasKey("user-agent") and client.userAgent != "":
client.headers["User-Agent"] = client.userAgent client.headers["User-Agent"] = client.userAgent
var headers = generateHeaders(r, $httpMethod, client.headers) var headers = generateHeaders(r, $httpMethod, client.headers, body)
await client.socket.send(headers) await client.socket.send(headers)
if body != "": if body != "":