thttpcore.nim 892 B

12345678910111213141516171819202122232425262728293031323334353637
  1. discard """
  2. output: "[Suite] httpcore"
  3. """
  4. import unittest
  5. import httpcore, strutils
  6. suite "httpcore":
  7. test "HttpCode":
  8. assert $Http418 == "418 I'm a teapot"
  9. assert Http418.is4xx() == true
  10. assert Http418.is2xx() == false
  11. test "headers":
  12. var h = newHttpHeaders()
  13. assert h.len == 0
  14. h.add("Cookie", "foo")
  15. assert h.len == 1
  16. assert h.hasKey("cooKIE")
  17. assert h["Cookie"] == "foo"
  18. assert h["cookie"] == "foo"
  19. h["cookie"] = @["bar", "x"]
  20. assert h["Cookie"] == "bar"
  21. assert h["Cookie", 1] == "x"
  22. assert h["Cookie"].contains("BaR") == true
  23. assert h["Cookie"].contains("X") == true
  24. assert "baR" in h["cookiE"]
  25. h.del("coOKie")
  26. assert h.len == 0
  27. # Test that header constructor works with repeated values
  28. let h1 = newHttpHeaders({"a": "1", "a": "2", "A": "3"})
  29. assert seq[string](h1["a"]).join(",") == "1,2,3"