Add HTTP header deletion, improve tests

This commit is contained in:
Federico Ceratto
2016-12-01 00:10:43 +00:00
parent 8494338bcb
commit 74e442f766
2 changed files with 32 additions and 0 deletions

View File

@@ -154,6 +154,10 @@ proc add*(headers: HttpHeaders, key, value: string) =
else:
headers.table[key.toLowerAscii].add(value)
proc del*(headers: HttpHeaders, key: string) =
## Delete the header entries associated with ``key``
headers.table.del(key.toLowerAscii)
iterator pairs*(headers: HttpHeaders): tuple[key, value: string] =
## Yields each key, value pair.
for k, v in headers.table:

View File

@@ -0,0 +1,28 @@
import unittest
import httpcore
suite "httpcore":
test "HttpCode":
assert $Http418 == "418 I'm a teapot"
assert Http418.is4xx() == true
assert Http418.is2xx() == false
test "headers":
var h = newHttpHeaders()
assert h.len == 0
h.add("Cookie", "foo")
assert h.len == 1
assert h.hasKey("cooKIE")
assert h["Cookie"] == "foo"
assert h["cookie"] == "foo"
h["cookie"] = @["bar", "x"]
assert h["Cookie"] == "bar"
assert h["Cookie", 1] == "x"
assert h["Cookie"].contains("BaR") == true
assert h["Cookie"].contains("X") == true
assert "baR" in h["cookiE"]
h.del("coOKie")
assert h.len == 0