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.