Fix missing decodeUrl() while decoding CommaSeparatedArray URL query parameters. (#360)

Fix unused `exc` warnings.
Fix unused ContentDisposition warning.
This commit is contained in:
Eugene Kabanov 2023-02-17 12:52:54 +02:00 committed by GitHub
parent a50ac4f642
commit 77ffff322c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 54 deletions

View File

@ -1039,7 +1039,7 @@ proc send*(request: HttpClientRequestRef): Future[HttpClientResponseRef] {.
except CancelledError as exc:
request.setError(newHttpInterruptError())
raise exc
except AsyncStreamError as exc:
except AsyncStreamError:
let error = newHttpWriteError("Could not send request headers")
request.setError(error)
raise error
@ -1084,7 +1084,7 @@ proc open*(request: HttpClientRequestRef): Future[HttpBodyWriter] {.
except CancelledError as exc:
request.setError(newHttpInterruptError())
raise exc
except AsyncStreamError as exc:
except AsyncStreamError:
let error = newHttpWriteError("Could not send request headers")
request.setError(error)
raise error
@ -1208,7 +1208,7 @@ proc getBodyBytes*(response: HttpClientResponseRef): Future[seq[byte]] {.
await reader.closeWait()
response.setError(newHttpInterruptError())
raise exc
except AsyncStreamError as exc:
except AsyncStreamError:
if not(isNil(reader)):
await reader.closeWait()
let error = newHttpReadError("Could not read response")
@ -1233,7 +1233,7 @@ proc getBodyBytes*(response: HttpClientResponseRef,
await reader.closeWait()
response.setError(newHttpInterruptError())
raise exc
except AsyncStreamError as exc:
except AsyncStreamError:
if not(isNil(reader)):
await reader.closeWait()
let error = newHttpReadError("Could not read response")
@ -1256,7 +1256,7 @@ proc consumeBody*(response: HttpClientResponseRef): Future[int] {.async.} =
await reader.closeWait()
response.setError(newHttpInterruptError())
raise exc
except AsyncStreamError as exc:
except AsyncStreamError:
if not(isNil(reader)):
await reader.closeWait()
let error = newHttpReadError("Could not read response")

View File

@ -7,7 +7,7 @@
# Apache License, version 2.0, (LICENSE-APACHEv2)
# MIT license (LICENSE-MIT)
import std/[strutils, uri]
import stew/[results, endians2], httputils
import stew/results, httputils
import ../../asyncloop, ../../asyncsync
import ../../streams/[asyncstream, boundstream]
export asyncloop, asyncsync, results, httputils, strutils
@ -125,9 +125,8 @@ iterator queryParams*(query: string,
if len(k) > 0:
let v = if len(items) > 1: items[1] else: ""
if CommaSeparatedArray in flags:
let key = decodeUrl(k)
for av in decodeUrl(v).split(','):
yield (k, av)
yield (decodeUrl(k), av)
else:
yield (decodeUrl(k), decodeUrl(v))
@ -249,48 +248,3 @@ func stringToBytes*(src: openArray[char]): seq[byte] =
dst
else:
default
proc dumpHex*(pbytes: openArray[byte], groupBy = 1, ascii = true): string =
## Get hexadecimal dump of memory for array ``pbytes``.
var res = ""
var offset = 0
var ascii = ""
while offset < len(pbytes):
if (offset mod 16) == 0:
res = res & toHex(uint64(offset)) & ": "
for k in 0 ..< groupBy:
let ch = pbytes[offset + k]
ascii.add(if ord(ch) > 31 and ord(ch) < 127: char(ch) else: '.')
let item =
case groupBy:
of 1:
toHex(pbytes[offset])
of 2:
toHex(uint16.fromBytes(pbytes.toOpenArray(offset, len(pbytes) - 1)))
of 4:
toHex(uint32.fromBytes(pbytes.toOpenArray(offset, len(pbytes) - 1)))
of 8:
toHex(uint64.fromBytes(pbytes.toOpenArray(offset, len(pbytes) - 1)))
else:
""
res.add(item)
res.add(" ")
offset = offset + groupBy
if (offset mod 16) == 0:
res.add(" ")
res.add(ascii)
ascii.setLen(0)
res.add("\p")
if (offset mod 16) != 0:
let spacesCount = ((16 - (offset mod 16)) div groupBy) *
(groupBy * 2 + 1) + 1
res = res & repeat(' ', spacesCount)
res = res & ascii
res.add("\p")
res

View File

@ -604,7 +604,6 @@ proc beginPart*(mpw: MultiPartWriterRef, name: string,
## output stream.
##
## Note: `filename` and `name` arguments could be only ASCII strings.
const ContentDisposition = "Content-Disposition"
doAssert(mpw.kind == MultiPartSource.Stream)
doAssert(mpw.state in {MultiPartWriterState.MessageStarted,
MultiPartWriterState.PartFinished})