mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-06 20:04:18 +00:00
post should work when extra headers don't have trailing newline
This commit is contained in:
@@ -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 = ""
|
||||
|
||||
Reference in New Issue
Block a user