Merge pull request #5080 from FedericoCeratto/httpheaders
Add HTTP header deletion, improve tests
This commit is contained in:
commit
d6ab21eed5
2 changed files with 32 additions and 0 deletions
|
|
@ -154,6 +154,10 @@ proc add*(headers: HttpHeaders, key, value: string) =
|
||||||
else:
|
else:
|
||||||
headers.table[key.toLowerAscii].add(value)
|
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] =
|
iterator pairs*(headers: HttpHeaders): tuple[key, value: string] =
|
||||||
## Yields each key, value pair.
|
## Yields each key, value pair.
|
||||||
for k, v in headers.table:
|
for k, v in headers.table:
|
||||||
|
|
|
||||||
28
tests/stdlib/thttpcore.nim
Normal file
28
tests/stdlib/thttpcore.nim
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue