From c4cc907433a3ac2e5373cb0190ece145bfc047bb Mon Sep 17 00:00:00 2001 From: flywind <43030857+xflywind@users.noreply.github.com> Date: Thu, 5 Nov 2020 21:01:28 +0800 Subject: fix adding empty sequence to HTTP headers (#15783) * fix adding empty sequence to HTTP headers * add tests --- lib/pure/httpcore.nim | 11 +++++++---- tests/stdlib/thttpcore.nim | 27 +++++++++++++++++++++++++++ 2 files changed, 34 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] = diff --git a/tests/stdlib/thttpcore.nim b/tests/stdlib/thttpcore.nim index 33c24453e..cb1a0875f 100644 --- a/tests/stdlib/thttpcore.nim +++ b/tests/stdlib/thttpcore.nim @@ -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") -- cgit 1.4.1-2-gfad0 ='#n5'>5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
version 0.10.4
==============
- improve GC-unsafety warnings
- make 'nil' work for 'add' and 'len'
- get rid of 'mget'; aka priority of 'var' needs to be 'var{lvalue}'
- 'result' shadowing warning
version 1.0
===========
- nimsuggest: auto-completion needs to work in 'class' macros
- improve the docs for inheritance
- The bitwise 'not' operator will be renamed to 'bnot' to
prevent 'not 4 == 5' from compiling. -> requires 'mixin' annotation for procs!
- iterators always require a return type
- overloading of '='
- make nimble part of the distribution
- split docgen into separate tool
- special rule for ``[]=``, items, pairs
- BUG: echo with template `$`*(info: TLineInfo): expr = toFileLineCol(info)
Concurrency
-----------
- test 'deepCopy' for closures
- implement 'foo[1..4] = spawn(f[4..7])'
Low priority:
- support for exception propagation? (hard to implement)
- the copying of the 'ref Promise' into the thead local storage only
happens to work due to the write barrier's implementation
Misc
----
- make '--implicitStatic:on' the default
- make tuple unpacking work in a non-var/let context
- built-in 'getImpl'
- prevent 'alloc(TypeWithGCedMemory)'
Bugs
====
- VM: Pegs do not work at compile-time
- VM: ptr/ref T cannot work in general
- scopes are still broken for generic instantiation!
- compilation of niminst takes way too long. looks like a regression
- blocks can "export" an identifier but the CCG generates {} for them ...
version 0.9.x
=============
- allow simple read accesses to global variables --> difficult to ensure that
no data races happen
- pragmas need 'bindSym' support
- pragmas need re-work: 'push' is dangerous, 'hasPragma' does not work
reliably with user-defined pragmas
- memory manager: add a measure of fragmentation
- implement 'bits' pragmas
- we need a magic thisModule symbol
- optimize 'genericReset'; 'newException' leads to code bloat
- The 'do' notation might be trimmed so that its only purpose is to pass
multiple multi line constructs to a macro.
version 0.9.X
=============
- macros as type pragmas
- implement type API for macros
- lazy overloading resolution:
* special case ``tyStmt``
- document NimMain and check whether it works for threading
GC
==
- hybrid GC
- use big blocks in the allocator
- provide tool/API to track leaks/object counts
- resizing of strings/sequences could take into account the memory that
is allocated
CGEN
====
- codegen should use "NIM_CAST" macro and respect aliasing rules for GCC
- ``restrict`` pragma + backend support