Vertx doesn't honor "transfer-encoding" header

231 views
Skip to first unread message

Manish Kumar

unread,
Sep 19, 2017, 10:46:16 AM9/19/17
to vert.x
How to reproduce:  Add response header

httpServerResponse.headers().add("transfer-encoding", "chunked");


Then do :

httpServerResponse.write("something").end()


And it will throw following error:

java.lang.IllegalStateException: You must set the Content-Length header to be the total size of the message body BEFORE sending any data if you are not using HTTP chunked encoding.
at io.vertx.core.http.impl.HttpServerResponseImpl.write(HttpServerResponseImpl.java:601)
at io.vertx.core.http.impl.HttpServerResponseImpl.write(HttpServerResponseImpl.java:284)


This condition in HttpServerResponseImpl needs to be fixed:

if (!headWritten && version != HttpVersion.HTTP_1_0 && !chunked && !contentLengthSet()) {
throw new IllegalStateException("You must set the Content-Length header to be the total size of the message "
+ "body BEFORE sending any data if you are not using HTTP chunked encoding.");
}


We could do "setChunked(true)" but our app works as proxy and take remote server headers and write back as-is, and it's not a big deal for us to handle it ourselves but I think we should fix it in Vertx as well.


I can create PR if you guys agree. Let me know.

Julien Viet

unread,
Sep 19, 2017, 11:33:34 AM9/19/17
to ve...@googlegroups.com
Hi,

please open an issue for this, it would be nice indeed to proceed this way.

Julien

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/18cee946-44c4-4ef4-bb98-564f59702f54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexander Lehmann

unread,
Sep 21, 2017, 6:32:18 AM9/21/17
to vert.x
I think I worked around that by setting setChunked(true) if the incoming response contained the chunked header, however this could be automatic (unless there is a reason for the original implementation, but I don't think so)

Julien Viet

unread,
Sep 21, 2017, 8:20:42 AM9/21/17
to ve...@googlegroups.com
That being said,

normally when you act as a proxy, you should not blindly convert all headers from the proxied server (https://www.mnot.net/blog/2011/07/11/what_proxies_must_do).

Julien


-- 
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
Reply all
Reply to author
Forward
0 new messages