Skip to content

Commit

Permalink
Fix #13573 and #13574 (#13575)
Browse files Browse the repository at this point in the history
* Fix #13573 and #13574

* Restored asynchttpserver
  • Loading branch information
andreaferretti authored Mar 6, 2020
1 parent 4bd388a commit 7ae0811
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/pure/httpcore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion tests/stdlib/thttpcore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ output: "[Suite] httpcore"

import unittest

import httpcore
import httpcore, strutils

suite "httpcore":

Expand All @@ -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"

0 comments on commit 7ae0811

Please sign in to comment.