summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-10-03 11:00:24 +0800
committerGitHub <noreply@github.com>2023-10-03 11:00:24 +0800
commit5d5c39e7452af71162c6d9b499dffe86d9c2d485 (patch)
tree0f302f98067a87e3f7d85ae39061da536d30ab8d
parent642ac0c1c31063ae966d8448c64c539203432e94 (diff)
downloadNim-5d5c39e7452af71162c6d9b499dffe86d9c2d485.tar.gz
fixes #22778 regression: contentLength implementation type mismatched (#22780)
fixes #22778
follow up https://github.com/nim-lang/Nim/pull/19835
-rw-r--r--lib/pure/httpclient.nim2
-rw-r--r--tests/stdlib/tasynchttpserver.nim1
2 files changed, 2 insertions, 1 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim
index ddf208e4e..9444618db 100644
--- a/lib/pure/httpclient.nim
+++ b/lib/pure/httpclient.nim
@@ -305,7 +305,7 @@ proc contentLength*(response: Response | AsyncResponse): int =
   ##
   ## A `ValueError` exception will be raised if the value is not an integer.
   ## If the Content-Length header is not set in the response, ContentLength is set to the value -1.
-  var contentLengthHeader = response.headers.getOrDefault("Content-Length", @["-1"])
+  var contentLengthHeader = response.headers.getOrDefault("Content-Length", HttpHeaderValues(@["-1"]))
   result = contentLengthHeader.parseInt()
 
 proc lastModified*(response: Response | AsyncResponse): DateTime =
diff --git a/tests/stdlib/tasynchttpserver.nim b/tests/stdlib/tasynchttpserver.nim
index 8cf0d0ced..5a7e2da40 100644
--- a/tests/stdlib/tasynchttpserver.nim
+++ b/tests/stdlib/tasynchttpserver.nim
@@ -109,6 +109,7 @@ proc testCustomContentLength() {.async.} =
     doAssert(body == "")
     doAssert(response.headers.hasKey("Content-Length"))
     doAssert(response.headers["Content-Length"] == "0")
+    doAssert contentLength(response) == 0 # bug #22778
 
   runTest(handler, request, test)