-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Made it possible to specify a Content-Length Header for a StreamedBody #6003
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
Made it possible to specify a Content-Length Header for a StreamedBody #6003
Conversation
|
Hello @schmitch, Could you please add some tests? |
| val playWsDeps = Seq( | ||
| guava, | ||
| "org.asynchttpclient" % "async-http-client" % "2.0.0-RC19" | ||
| "org.asynchttpclient" % "async-http-client" % "2.0.0-RC21" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version is using netty 4.0.36.Final. Do you mind also updating play version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I prefer to not upgrade that until playframework/netty-reactive-streams#10 is merged and released, but we could delay this PR until that happend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to wait for playframework/netty-reactive-streams#10 to upgrade Netty here because async-http-client will bring 4.0.36.Final and the older versions will be evicted.
|
@marcospereira I created unit tests however I needed to change something in |
| Server.withRouter() { | ||
| case _ => Action { req => | ||
| val headers = req.headers.toMap | ||
| Ok(s"${headers.get(CONTENT_LENGTH).isDefined}${headers.get(TRANSFER_ENCODING).isDefined}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of checking if the header is present, maybe is better check against its value. Something like this:
val contentLength = headers.get(CONTENT_LENGTH)
val transferEncoding = headers.get(TRANSFER_ENCODING)
Ok(s"Content-Length: ${contentLength.getOrElse(-1)}; Transfer-Encoding: ${transferEncoding.getOrElse(-1)}")Where -1 means the header is not present. Also, notice I've changed the response format to make test assertions more clear.
|
@schmitch about the two commits, since both are necessary to make it possible to specify a |
|
Actually they are not necessary to make it possible to specify a That's why I prefer two commits here. Edit: I edited what you wanted but I kept the commits for the reason above, but If you still prefer a squash I will do. |
Maybe we can separate that in another PR (which can safety be backported to 2.5.x) and keep this one focused only on make "possible to specify a Content-Length Header for a StreamedBody". I'm sorry if this adds more friction to this PR. |
|
@marcospereira It's not a problem at all I will ping you here when that is mergend and I rebased that one. |
|
@marcospereira there was a commit that fixed the Headers in Akka-http: So this should build now. Backport would be great but it's only possible after c0f1270 is backported. |
|
Backport to 2.5.x: a90bcd5 |
Purpose
Adds a way to set a manual Content-Length Header for Streaming Bodies, this could be useful if you want to send multipart/form data bodies to Clients that can't make use of Transfer-Encoding: chunked (i.e. WSGI)
Actually with this it's possible to manually provide the Content-Length however in the Future we could maybe create a way to determine it, but I doubt that this would break Mima.
i.e. I had tests that checked the headers but actually only on Netty or Akka (don't know which) the Content-Length/Transfer-Encoding will be in the Request Headers.
References
https://groups.google.com/forum/#!topic/play-framework/mcA7jmnCiAw
Needs Backport