parent
55b5401dc6
commit
5cf31417a6
1 changed files with 9 additions and 6 deletions
|
|
@ -434,7 +434,7 @@ proc `[]=`*(p: var MultipartData, name: string,
|
||||||
## "<html><head></head><body><p>test</p></body></html>")
|
## "<html><head></head><body><p>test</p></body></html>")
|
||||||
p.add(name, file.content, file.name, file.contentType)
|
p.add(name, file.content, file.name, file.contentType)
|
||||||
|
|
||||||
proc format(p: MultipartData): tuple[header, body: string] =
|
proc format(p: MultipartData): tuple[contentType, body: string] =
|
||||||
if p == nil or p.content == nil or p.content.len == 0:
|
if p == nil or p.content == nil or p.content.len == 0:
|
||||||
return ("", "")
|
return ("", "")
|
||||||
|
|
||||||
|
|
@ -449,7 +449,7 @@ proc format(p: MultipartData): tuple[header, body: string] =
|
||||||
if not found:
|
if not found:
|
||||||
break
|
break
|
||||||
|
|
||||||
result.header = "Content-Type: multipart/form-data; boundary=" & bound & "\c\L"
|
result.contentType = "multipart/form-data; boundary=" & bound
|
||||||
result.body = ""
|
result.body = ""
|
||||||
for s in p.content:
|
for s in p.content:
|
||||||
result.body.add("--" & bound & "\c\L" & s)
|
result.body.add("--" & bound & "\c\L" & s)
|
||||||
|
|
@ -640,7 +640,7 @@ proc post*(url: string, extraHeaders = "", body = "",
|
||||||
## ``multipart/form-data`` POSTs comfortably.
|
## ``multipart/form-data`` POSTs comfortably.
|
||||||
##
|
##
|
||||||
## **Deprecated since version 0.15.0**: use ``HttpClient.post`` instead.
|
## **Deprecated since version 0.15.0**: use ``HttpClient.post`` instead.
|
||||||
let (mpHeaders, mpBody) = format(multipart)
|
let (mpContentType, mpBody) = format(multipart)
|
||||||
|
|
||||||
template withNewLine(x): untyped =
|
template withNewLine(x): untyped =
|
||||||
if x.len > 0 and not x.endsWith("\c\L"):
|
if x.len > 0 and not x.endsWith("\c\L"):
|
||||||
|
|
@ -650,9 +650,12 @@ proc post*(url: string, extraHeaders = "", body = "",
|
||||||
|
|
||||||
var xb = mpBody.withNewLine() & body
|
var xb = mpBody.withNewLine() & body
|
||||||
|
|
||||||
var xh = extraHeaders.withNewLine() & mpHeaders.withNewLine() &
|
var xh = extraHeaders.withNewLine() &
|
||||||
withNewLine("Content-Length: " & $len(xb))
|
withNewLine("Content-Length: " & $len(xb))
|
||||||
|
|
||||||
|
if not multipart.isNil:
|
||||||
|
xh.add(withNewLine("Content-Type: " & mpContentType))
|
||||||
|
|
||||||
result = request(url, httpPOST, xh, xb, sslContext, timeout, userAgent,
|
result = request(url, httpPOST, xh, xb, sslContext, timeout, userAgent,
|
||||||
proxy)
|
proxy)
|
||||||
var lastURL = url
|
var lastURL = url
|
||||||
|
|
@ -1188,7 +1191,7 @@ proc post*(client: HttpClient | AsyncHttpClient, url: string, body = "",
|
||||||
##
|
##
|
||||||
## This procedure will follow redirects up to a maximum number of redirects
|
## This procedure will follow redirects up to a maximum number of redirects
|
||||||
## specified in ``client.maxRedirects``.
|
## specified in ``client.maxRedirects``.
|
||||||
let (mpHeader, mpBody) = format(multipart)
|
let (mpContentType, mpBody) = format(multipart)
|
||||||
# TODO: Support FutureStream for `body` parameter.
|
# TODO: Support FutureStream for `body` parameter.
|
||||||
template withNewLine(x): untyped =
|
template withNewLine(x): untyped =
|
||||||
if x.len > 0 and not x.endsWith("\c\L"):
|
if x.len > 0 and not x.endsWith("\c\L"):
|
||||||
|
|
@ -1199,7 +1202,7 @@ proc post*(client: HttpClient | AsyncHttpClient, url: string, body = "",
|
||||||
|
|
||||||
var headers = newHttpHeaders()
|
var headers = newHttpHeaders()
|
||||||
if multipart != nil:
|
if multipart != nil:
|
||||||
headers["Content-Type"] = mpHeader.split(": ")[1]
|
headers["Content-Type"] = mpContentType
|
||||||
headers["Content-Length"] = $len(xb)
|
headers["Content-Length"] = $len(xb)
|
||||||
|
|
||||||
result = await client.requestAux(url, $HttpPOST, xb, headers)
|
result = await client.requestAux(url, $HttpPOST, xb, headers)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue