diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2019-11-22 14:21:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-22 14:21:03 +0100 |
commit | e5478b32a891077972c53b0715481fb7c6b4390c (patch) | |
tree | 1f8e0e24b8746ea1333665f9ed9f2346ca3d1f1f | |
parent | 64e8f050e1fc88eadd96c9006b97e59d5edb5a94 (diff) | |
download | Nim-e5478b32a891077972c53b0715481fb7c6b4390c.tar.gz |
fixes #11863 multipart data need $ (#12707)
* fixes #11863 * improved the code; refs #12412
-rw-r--r-- | lib/pure/httpclient.nim | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 430e15c5a..d918be735 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -175,6 +175,8 @@ ## let client = newHttpClient(maxRedirects = 0) ## +include "system/inclrtl" + import net, strutils, uri, parseutils, base64, os, mimetypes, math, random, httpcore, times, tables, streams, std/monotimes import asyncnet, asyncdispatch, asyncfile @@ -297,6 +299,17 @@ proc newMultipartData*: MultipartData = ## Constructs a new ``MultipartData`` object. MultipartData(content: @[]) + +proc `$`*(data: MultipartData): string {.since: (1, 1).} = + ## convert MultipartData to string so it's human readable when echo + ## see https://github.com/nim-lang/Nim/issues/11863 + const prefixLen = "Content-Disposition: form-data; ".len + for pos, item in data.content: + result &= "------------------------------ " + result.addInt pos + result &= " ------------------------------\n" + result &= item[prefixLen .. item.high] + proc add*(p: var MultipartData, name, content: string, filename: string = "", contentType: string = "") = ## Add a value to the multipart data. Raises a `ValueError` exception if |