fixes #11863 multipart data need $ (#12707)

* fixes #11863
* improved the code; refs #12412
This commit is contained in:
Andreas Rumpf
2019-11-22 14:21:03 +01:00
committed by GitHub
parent 64e8f050e1
commit e5478b32a8

View File

@@ -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