Skip to content

Strange behavior with HttpServerResponse headers().put() and putHeader() #164

@Narigo

Description

@Narigo

There is a difference between req.response().headers().put(...) and req.response().putHeader(...): The former adds values and the latter overrides everything.

For example, I want to add multiple cookies into a request.

This implementation works as intended:

def addSomeCookie(req: HttpServerRequest, key: String, value: String) =
  req.response().headers().put("Set-Cookie", collection.mutable.Set(s"${urlEncode(key)}=${urlEncode(value)}"))

While this implementation overwrites all previous cookies:

def addSomeCookie(req: HttpServerRequest, key: String, value: String) =
  req.response().putHeader("Set-Cookie", s"${urlEncode(key)}=${urlEncode(value)}")

It would be a lot better if these two methods had either different names or would behave the same way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions