mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
fix adding empty sequence to HTTP headers (#15783)
* fix adding empty sequence to HTTP headers * add tests
This commit is contained in:
@@ -166,9 +166,12 @@ proc `[]=`*(headers: HttpHeaders, key, value: string) =
|
||||
|
||||
proc `[]=`*(headers: HttpHeaders, key: string, value: seq[string]) =
|
||||
## Sets the header entries associated with ``key`` to the specified list of
|
||||
## values.
|
||||
## Replaces any existing values.
|
||||
headers.table[headers.toCaseInsensitive(key)] = value
|
||||
## values. Replaces any existing values. If ``value`` is empty,
|
||||
## deletes the header entries associated with ``key``.
|
||||
if value.len > 0:
|
||||
headers.table[headers.toCaseInsensitive(key)] = value
|
||||
else:
|
||||
headers.table.del(headers.toCaseInsensitive(key))
|
||||
|
||||
proc add*(headers: HttpHeaders, key, value: string) =
|
||||
## Adds the specified value to the specified key. Appends to any existing
|
||||
@@ -179,7 +182,7 @@ proc add*(headers: HttpHeaders, key, value: string) =
|
||||
headers.table[headers.toCaseInsensitive(key)].add(value)
|
||||
|
||||
proc del*(headers: HttpHeaders, key: string) =
|
||||
## Delete the header entries associated with ``key``
|
||||
## Deletes the header entries associated with ``key``
|
||||
headers.table.del(headers.toCaseInsensitive(key))
|
||||
|
||||
iterator pairs*(headers: HttpHeaders): tuple[key, value: string] =
|
||||
|
||||
Reference in New Issue
Block a user