* Fix https://github.com/nim-lang/Nim/issues/13573 and https://github.com/nim-lang/Nim/issues/13574 * Restored asynchttpserver
This commit is contained in:
parent
4bd388ad58
commit
7ae0811818
2 changed files with 14 additions and 5 deletions
|
|
@ -105,11 +105,15 @@ proc newHttpHeaders*(): HttpHeaders =
|
||||||
|
|
||||||
proc newHttpHeaders*(keyValuePairs:
|
proc newHttpHeaders*(keyValuePairs:
|
||||||
openArray[tuple[key: string, val: string]]): HttpHeaders =
|
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
|
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 =
|
proc `$`*(headers: HttpHeaders): string =
|
||||||
return $headers.table
|
return $headers.table
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ output: "[Suite] httpcore"
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import httpcore
|
import httpcore, strutils
|
||||||
|
|
||||||
suite "httpcore":
|
suite "httpcore":
|
||||||
|
|
||||||
|
|
@ -29,3 +29,8 @@ suite "httpcore":
|
||||||
assert "baR" in h["cookiE"]
|
assert "baR" in h["cookiE"]
|
||||||
h.del("coOKie")
|
h.del("coOKie")
|
||||||
assert h.len == 0
|
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"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue