Change the content length calculation to match the http spec
For reference: https://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html#Entity-Body
This commit is contained in:
parent
944a0ac318
commit
ab5d77f972
1 changed files with 5 additions and 2 deletions
|
|
@ -980,8 +980,11 @@ proc requestAux(client: HttpClient | AsyncHttpClient, url, httpMethod: string,
|
||||||
var data: seq[string]
|
var data: seq[string]
|
||||||
if multipart != nil and multipart.content.len > 0:
|
if multipart != nil and multipart.content.len > 0:
|
||||||
data = await client.format(multipart)
|
data = await client.format(multipart)
|
||||||
elif httpMethod in ["POST", "PATCH", "PUT", "DELETE"] or body.len != 0:
|
else:
|
||||||
client.headers["Content-Length"] = $body.len
|
if body.len != 0:
|
||||||
|
client.headers["Content-Length"] = $body.len
|
||||||
|
elif httpMethod notin ["GET", "HEAD"] and not client.headers.hasKey("Content-Length"):
|
||||||
|
client.headers["Content-Length"] = "0"
|
||||||
|
|
||||||
when client is AsyncHttpClient:
|
when client is AsyncHttpClient:
|
||||||
if not client.parseBodyFut.isNil:
|
if not client.parseBodyFut.isNil:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue