diff options
author | def <dennis@felsin9.de> | 2015-01-05 01:55:52 +0100 |
---|---|---|
committer | def <dennis@felsin9.de> | 2015-01-05 01:55:52 +0100 |
commit | d4955090ae4b18780e5b7b5333eba619622d0e1b (patch) | |
tree | 2b2723838afdaa24097b6887771be4ad9147fe29 /lib/pure | |
parent | a90c388f6bad1e5bfcdcb71d1ce271206c12bf24 (diff) | |
download | Nim-d4955090ae4b18780e5b7b5333eba619622d0e1b.tar.gz |
post should work when extra headers don't have trailing newline
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/httpclient.nim | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 3ab56cddf..f95242a32 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -494,8 +494,17 @@ proc post*(url: string, extraHeaders = "", body = "", ## ``multipart/form-data`` POSTs comfortably. let (mpHeaders, mpBody) = format(multipart) - var xb = mpBody & body - var xh = extraHeaders & mpHeaders & "Content-Length: " & $len(xb) & "\c\L" + template withNewLine(x): expr = + if x.len > 0 and not x.endsWith("\c\L"): + x & "\c\L" + else: + x + + var xb = mpBody.withNewLine() & body.withNewLine() + + var xh = extraHeaders.withNewLine() & mpHeaders.withNewLine() & + withNewLine("Content-Length: " & $len(xb)) + result = request(url, httpPOST, xh, xb, sslContext, timeout, userAgent, proxy) var lastUrl = "" |