Allow for multiple HTTP headers with same field name in ResponseHeader
See original GitHub issueAre you looking for help?
Following up the discussion on glitter channel https://gitter.im/lagom/lagom?at=59bfcc2d7b7d98d30d0d3005
Lagom Version (1.2.x / 1.3.x / etc)
1.4.0-M2
API (Scala / Java / Neither / Both)
Scala
Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)
MacOS 10.12.6 (16G29)
JDK (Oracle 1.8.0_112, OpenJDK 1.8.x, Azul Zing)
Oracle 1.8.0_111
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
Expected Behavior
- Define a service implementation such as
def method: ServerServiceCall[NotUsed, Done] = ServerServiceCall { (_, _) =>
Future.successful((ResponseHeader.Ok
.withHeader("Set-Cookie", s"cookie1=One; Path=/;")
.addHeader("Set-cookie", s"cookie2=Two; Path=/;"),
Done))
}
Suspected behavior also appears with this definition
def method: ServerServiceCall[NotUsed, Done] = ServerServiceCall { (_, _) =>
Future.successful((ResponseHeader.Ok.withHeaders(immutable.Seq(
("Set-Cookie", s"cookie1=One; Path=/;"),
("Set-cookie", s"cookie2=Two; Path=/;")
)),
Done))
}
- Wire it as a REST call with the descriptor in the api
override final def descriptor = {
import Service._
named("SomeService").withCalls(
restCall(Method.GET, "/api/method", method _)
).withAutoAcl(true)
}
- Start lagom server
$ sbt runAll
- Call the rest endpoint and get both
set-cookie
headers in the response
$ curl -v -X GET http://localhost:9000/api/method
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> PUT /api/logout HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< set-cookie: cookie1=One; Path=/
< set-cookie: cookie2=Two; Path=/
< Date: Mon, 18 Sep 2017 13:39:41 GMT
< Server: akka-http/10.0.9
< Content-Length: 0
<
* Connection #0 to host localhost left intact
Actual Behavior
$ curl -v -X GET http://localhost:9000/api/method
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> PUT /api/logout HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< set-cookie: cookie1=One; Path=/
< Date: Mon, 18 Sep 2017 13:39:41 GMT
< Server: akka-http/10.0.9
< Content-Length: 0
<
* Connection #0 to host localhost left intact
The response HTTP headers only contains one occurence of “set-cookie” header, the first defined.
As RFC 6265 states its required to use multiple occurence of headers with the same field name for set-cookie
. Others HTTP headers will probably fall in the same case (most notably those from X-
non-standards headers)
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Standard for adding multiple values of a single HTTP Header ...
It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message ...
Read more >Access multi-value HTTP headers incorrectly in an API Proxy ...
The HTTP headers are the name value pairs that allow the client ... The HTTP Headers can have one or more values depending...
Read more >Access-Control-Allow-Headers - HTTP - MDN Web Docs
The Access-Control-Allow-Headers response header is used in response to a preflight request which includes the ...
Read more >Multiple header values with the same name - HTTPie
If the request is sent with multiple headers that are sharing the same name, then the HTTPie will send them individually. http --offline...
Read more >Setting multiple response headers with same name, different ...
So IIS dooesn't allow custom response headers with same name. In the http specification: Multiple message-header fields with the same field-name ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was just about to reply with exactly the same thing. Play unfolds
Set-Cookie
headers here:https://github.com/playframework/playframework/blob/8a660fc12d359e8e005ffc368883ee5124262d0e/framework/src/play-server/src/main/scala/play/core/server/common/ServerResultUtils.scala#L237
At its core I believe this is a Play issue, not a Lagom one. There is some context here: https://github.com/playframework/playframework/issues/3279
This is not really a problem for Play users because Play already has a high-level API to handle cookies, for example:
Lagom has it’s own
ResponseHeader
that wraps Play’s, and doesn’t have any explicit handling for cookies.As a workaround, I think it should work to use a single
Set-Cookie
header with;;
separating the cookies:cookie1=One;Path=/;;cookie2=Two;Path=/
. The server should “unfold” those cookies and serve them as separate cookie headers.