post should work when extra headers don't have trailing newline
This commit is contained in:
parent
a90c388f6b
commit
d4955090ae
1 changed files with 11 additions and 2 deletions
|
|
@ -494,8 +494,17 @@ proc post*(url: string, extraHeaders = "", body = "",
|
||||||
## ``multipart/form-data`` POSTs comfortably.
|
## ``multipart/form-data`` POSTs comfortably.
|
||||||
let (mpHeaders, mpBody) = format(multipart)
|
let (mpHeaders, mpBody) = format(multipart)
|
||||||
|
|
||||||
var xb = mpBody & body
|
template withNewLine(x): expr =
|
||||||
var xh = extraHeaders & mpHeaders & "Content-Length: " & $len(xb) & "\c\L"
|
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,
|
result = request(url, httpPOST, xh, xb, sslContext, timeout, userAgent,
|
||||||
proxy)
|
proxy)
|
||||||
var lastUrl = ""
|
var lastUrl = ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue