summary refs log tree commit diff stats
path: root/lib/pure/httpcore.nim
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2020-11-05 21:01:28 +0800
committerGitHub <noreply@github.com>2020-11-05 14:01:28 +0100
commitc4cc907433a3ac2e5373cb0190ece145bfc047bb (patch)
treedd32c654aa2afe465f53a0df69fc16c566aafa56 /lib/pure/httpcore.nim
parent8e1fa84b0d44bc6fb995992becf659d62b36713a (diff)
downloadNim-c4cc907433a3ac2e5373cb0190ece145bfc047bb.tar.gz
fix adding empty sequence to HTTP headers (#15783)
* fix adding empty sequence to HTTP headers

* add tests
Diffstat (limited to 'lib/pure/httpcore.nim')
-rw-r--r--lib/pure/httpcore.nim11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/pure/httpcore.nim b/lib/pure/httpcore.nim
index af1bfc088..d796c788d 100644
--- a/lib/pure/httpcore.nim
+++ b/lib/pure/httpcore.nim
@@ -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] =