summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@gmail.com>2017-04-15 09:03:12 +0200
committerDominik Picheta <dominikpicheta@gmail.com>2017-04-15 09:03:12 +0200
commit5cf31417a6fcbe5a40bce792652fc05fc6a1cff9 (patch)
treebd5fffe69de960339b61158833db5066bd30be8e /lib
parent55b5401dc6ac0b42db1cca9f9dd50f3e19e3dbc0 (diff)
downloadNim-5cf31417a6fcbe5a40bce792652fc05fc6a1cff9.tar.gz
Fixes #5710. Closes #5711.
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/httpclient.nim15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim
index 62c7e2067..20b76503e 100644
--- a/lib/pure/httpclient.nim
+++ b/lib/pure/httpclient.nim
@@ -434,7 +434,7 @@ proc `[]=`*(p: var MultipartData, name: string,
   ##     "<html><head></head><body><p>test</p></body></html>")
   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:
     return ("", "")
 
@@ -449,7 +449,7 @@ proc format(p: MultipartData): tuple[header, body: string] =
     if not found:
       break
 
-  result.header = "Content-Type: multipart/form-data; boundary=" & bound & "\c\L"
+  result.contentType = "multipart/form-data; boundary=" & bound
   result.body = ""
   for s in p.content:
     result.body.add("--" & bound & "\c\L" & s)
@@ -640,7 +640,7 @@ proc post*(url: string, extraHeaders = "", body = "",
   ## ``multipart/form-data`` POSTs comfortably.
   ##
   ## **Deprecated since version 0.15.0**: use ``HttpClient.post`` instead.
-  let (mpHeaders, mpBody) = format(multipart)
+  let (mpContentType, mpBody) = format(multipart)
 
   template withNewLine(x): untyped =
     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 xh = extraHeaders.withNewLine() & mpHeaders.withNewLine() &
+  var xh = extraHeaders.withNewLine() &
     withNewLine("Content-Length: " & $len(xb))
 
+  if not multipart.isNil:
+    xh.add(withNewLine("Content-Type: " & mpContentType))
+
   result = request(url, httpPOST, xh, xb, sslContext, timeout, userAgent,
                    proxy)
   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
   ## specified in ``client.maxRedirects``.
-  let (mpHeader, mpBody) = format(multipart)
+  let (mpContentType, mpBody) = format(multipart)
   # TODO: Support FutureStream for `body` parameter.
   template withNewLine(x): untyped =
     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()
   if multipart != nil:
-    headers["Content-Type"] = mpHeader.split(": ")[1]
+    headers["Content-Type"] = mpContentType
   headers["Content-Length"] = $len(xb)
 
   result = await client.requestAux(url, $HttpPOST, xb, headers)