summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFederico Ceratto <federico.ceratto@gmail.com>2016-12-01 00:10:43 +0000
committerFederico Ceratto <federico.ceratto@gmail.com>2016-12-01 00:11:59 +0000
commit74e442f766183237e8edca7bb68dca1da81a7d9f (patch)
treef278d4195df5b8970778f1dcb512f4f4074e36a0
parent8494338bcbe1ffbd9845a6a5318d0853952b25d0 (diff)
downloadNim-74e442f766183237e8edca7bb68dca1da81a7d9f.tar.gz
Add HTTP header deletion, improve tests
-rw-r--r--lib/pure/httpcore.nim4
-rw-r--r--tests/stdlib/thttpcore.nim28
2 files changed, 32 insertions, 0 deletions
diff --git a/lib/pure/httpcore.nim b/lib/pure/httpcore.nim
index 8147f1c50..48001ccaa 100644
--- a/lib/pure/httpcore.nim
+++ b/lib/pure/httpcore.nim
@@ -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:
diff --git a/tests/stdlib/thttpcore.nim b/tests/stdlib/thttpcore.nim
new file mode 100644
index 000000000..9f99df93a
--- /dev/null
+++ b/tests/stdlib/thttpcore.nim
@@ -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