diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2015-06-08 23:10:50 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2015-06-08 23:10:50 +0100 |
commit | c4009c61820190c188f6bcf7469754b3c40201e5 (patch) | |
tree | b5ebc7551f70d32e135e4c70e44e36c8a47fbfe8 /lib/pure | |
parent | bbb1bdb4a939aa43ed981acc2f96bce918be7d21 (diff) | |
download | Nim-c4009c61820190c188f6bcf7469754b3c40201e5.tar.gz |
Fixes #2884
Haven't tested this patch but should work.
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/httpclient.nim | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index e083d44ea..6a2913713 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -569,7 +569,7 @@ proc downloadFile*(url: string, outputFilename: string, fileError("Unable to open file") 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. result = substr(httpMethod, len("http")) # TODO: Proxies @@ -582,6 +582,8 @@ proc generateHeaders(r: Uri, httpMethod: string, add(result, "Host: " & r.hostname & "\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: 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 != "": 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) if body != "": |