From 5d5c39e7452af71162c6d9b499dffe86d9c2d485 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 3 Oct 2023 11:00:24 +0800 Subject: [PATCH] fixes #22778 regression: contentLength implementation type mismatched (#22780) fixes #22778 follow up https://github.com/nim-lang/Nim/pull/19835 --- lib/pure/httpclient.nim | 2 +- tests/stdlib/tasynchttpserver.nim | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index ddf208e4e3..9444618db6 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 8cf0d0cedb..5a7e2da401 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)