vert-x / mod-lang-scala

Vert.x 2.x is deprecated - use instead
https://github.com/vert-x3/vertx-lang-scala
Apache License 2.0
77 stars 29 forks source link

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

Open Narigo opened 10 years ago

Narigo commented 10 years ago

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.

galderz commented 10 years ago

I think you make a good point, can you add some tests and possibly a fix? At first glance, we could implement putHeader() so that it delegates to req.response().headers().put(...) and that should work? Do you want me to assign this to you? Btw, this would be only for master, not 1.0.x.