fix adding empty sequence to HTTP headers (#15783)

* fix adding empty sequence to HTTP headers

* add tests
This commit is contained in:
flywind
2020-11-05 21:01:28 +08:00
committed by GitHub
parent 8e1fa84b0d
commit c4cc907433
2 changed files with 34 additions and 4 deletions

View File

@@ -51,3 +51,30 @@ suite "httpcore":
doAssert parseHeader("Accept: foo, bar") == (key: "Accept", value: @["foo", "bar"])
doAssert parseHeader("Accept: foo, bar, prologue") == (key: "Accept", value: @["foo", "bar", "prologue"])
doAssert parseHeader("Accept: foo, bar, prologue, starlight") == (key: "Accept", value: @["foo", "bar", "prologue", "starlight"])
test "add empty sequence to HTTP headers":
block:
var headers = newHttpHeaders()
headers["empty"] = @[]
doAssert not headers.hasKey("empty")
block:
var headers = newHttpHeaders()
headers["existing"] = "true"
headers["existing"] = @[]
doAssert not headers.hasKey("existing")
block:
var headers = newHttpHeaders()
headers["existing"] = @["true"]
headers["existing"] = @[]
doAssert not headers.hasKey("existing")
block:
var headers = newHttpHeaders()
headers["existing"] = @[]
headers["existing"] = @["true"]
doAssert headers.hasKey("existing")