Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@schmitch
Copy link
Contributor

@schmitch schmitch commented Apr 7, 2016

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

@marcospereira
Copy link
Member

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"
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

@schmitch
Copy link
Contributor Author

schmitch commented Apr 7, 2016

@marcospereira I created unit tests however I needed to change something in play-akka-http since the Content-Length header wasn't exposed. I kept it as another commit so that this PR has two commits now, is that fine for you?

Server.withRouter() {
case _ => Action { req =>
val headers = req.headers.toMap
Ok(s"${headers.get(CONTENT_LENGTH).isDefined}${headers.get(TRANSFER_ENCODING).isDefined}")
Copy link
Member

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.

@marcospereira
Copy link
Member

@schmitch about the two commits, since both are necessary to make it possible to specify a Content-Length Header for a StreamedBody, then I think you should squash them with a clear commit message. :-)

@schmitch
Copy link
Contributor Author

schmitch commented Apr 8, 2016

Actually they are not necessary to make it possible to specify a Content-Length header.
One commit is more or less a Bug in play-akka-http Actually play-netty adds the Content-Lengt or Transfer-Encoding header to the Action, but play-akka-http does not, so the ws tests would fail for the Akka Http Parts. But as said it's actually not related and the Content-Length header would work.

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.

@marcospereira
Copy link
Member

One commit is more or less a Bug in play-akka-http.

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.

@schmitch
Copy link
Contributor Author

@marcospereira It's not a problem at all cherry-pick ftw.
I made the PR here: #6014

I will ping you here when that is mergend and I rebased that one.

@schmitch
Copy link
Contributor Author

@marcospereira there was a commit that fixed the Headers in Akka-http:
c0f1270

So this should build now.

Backport would be great but it's only possible after c0f1270 is backported.

@marcospereira
Copy link
Member

@schmitch see #6023.

@marcospereira
Copy link
Member

Backport to 2.5.x: a90bcd5

@gmethvin gmethvin added this to the 2.5.2 milestone Apr 15, 2016
@schmitch schmitch deleted the streamable-content-length branch July 20, 2016 06:57
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

Successfully merging this pull request may close these issues.

3 participants