Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes 11863 multipart data need $ #12707

Merged
merged 3 commits into from
Nov 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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