Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Narigo opened this issue Jun 26, 2014 · 1 comment
Open

Comments

@Narigo
Copy link
Member

Narigo commented Jun 26, 2014

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
Copy link
Contributor

galderz commented Jul 18, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants