From e5478b32a891077972c53b0715481fb7c6b4390c Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 22 Nov 2019 14:21:03 +0100 Subject: fixes #11863 multipart data need $ (#12707) * fixes #11863 * improved the code; refs #12412 --- lib/pure/httpclient.nim | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 -- cgit 1.4.1-2-gfad0