From 7ae081181831dcfe8ab83811f2b209c552c61fc7 Mon Sep 17 00:00:00 2001 From: Andrea Ferretti Date: Fri, 6 Mar 2020 19:38:56 +0100 Subject: [PATCH] Fix #13573 and #13574 (#13575) * Fix https://github.com/nim-lang/Nim/issues/13573 and https://github.com/nim-lang/Nim/issues/13574 * Restored asynchttpserver --- lib/pure/httpcore.nim | 12 ++++++++---- tests/stdlib/thttpcore.nim | 7 ++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/pure/httpcore.nim b/lib/pure/httpcore.nim index 1e9a85a57..e6e0d35c4 100644 --- a/lib/pure/httpcore.nim +++ b/lib/pure/httpcore.nim @@ -105,11 +105,15 @@ proc newHttpHeaders*(): HttpHeaders = proc newHttpHeaders*(keyValuePairs: openArray[tuple[key: string, val: string]]): HttpHeaders = - var pairs: seq[tuple[key: string, val: seq[string]]] = @[] - for pair in keyValuePairs: - pairs.add((pair.key.toLowerAscii(), @[pair.val])) new result - result.table = newTable[string, seq[string]](pairs) + result.table = newTable[string, seq[string]]() + for pair in keyValuePairs: + let key = pair.key.toLowerAscii() + if key in result.table: + result.table[key].add(pair.val) + else: + result.table[key] = @[pair.val] + proc `$`*(headers: HttpHeaders): string = return $headers.table diff --git a/tests/stdlib/thttpcore.nim b/tests/stdlib/thttpcore.nim index 889c734c5..f96fcc3b8 100644 --- a/tests/stdlib/thttpcore.nim +++ b/tests/stdlib/thttpcore.nim @@ -4,7 +4,7 @@ output: "[Suite] httpcore" import unittest -import httpcore +import httpcore, strutils suite "httpcore": @@ -29,3 +29,8 @@ suite "httpcore": assert "baR" in h["cookiE"] h.del("coOKie") assert h.len == 0 + + # Test that header constructor works with repeated values + let h1 = newHttpHeaders({"a": "1", "a": "2", "A": "3"}) + + assert seq[string](h1["a"]).join(",") == "1,2,3"