Skip to content

Commit

Permalink
fixes #11863 multipart data need $ (#12707)
Browse files Browse the repository at this point in the history
* fixes #11863
* improved the code; refs #12412
  • Loading branch information
Araq authored Nov 22, 2019
1 parent 64e8f05 commit e5478b3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/pure/httpclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e5478b3

Please sign in to comment.