Skip to content

newHttpHeaders does not accept repeated headers #13573

Closed
@andreaferretti

Description

@andreaferretti

In httpcore, the constructor newHttpHeaders does not accept repeated headers. httpcore was recently refactored to add support for repeated headers - in particular we have types HttpHeaders and HttpHeaderValues, where before headers were just a stringTable.

Still, the constructor newHttpHeaders assumes that each header is passed a single time, as seen here:

proc newHttpHeaders*(keyValuePairs:
    openArray[tuple[key: string, val: string]]): HttpHeaders =
  var pairs: seq[tuple[key: string, val: seq[string]]] = @[]
  for pair in keyValuePairs:
    pairs.add((pair.key.toLowerAscii(), @[pair.val]))
  new result
  result.table = newTable[string, seq[string]](pairs)

To check this behaviour it is enough to do

import httpcore, strutils

let h = newHttpHeaders({"a": "1", "a": "2"})

assert seq[string](h["a"]).join(",") == "1,2"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions