mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
Add HTTP header deletion, improve tests
This commit is contained in:
@@ -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:
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user