perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.64k stars 1.56k forks source link

204 (no content) without content-type header not possible in 2.7.2? #1022

Open mroloux opened 6 years ago

mroloux commented 6 years ago

After upgrading from Spark 2.5.5 to 2.7.2, I'm not able to send a 204 response without a content-type header anymore. This worked fine in 2.5.5

The controller code looks like this:

response.status(204); response.type(""); return "";

The cause seems to be the following:

Spark 2.5.5 came with Jetty 9.3. In that Jetty version, headers that are empty strings or null are omitted from the response. That has changed with Jetty 9.4 (which is included in Spark 2.7.2): headers with empty strings are included as is in the responses.

response.type(null) would be a solution, but spark.http.matching.Body.seralizeTo() replaces null content types with text/html; charset=utf-8. Some HTTP clients don't like this. E.g. Jersey errors out when it receives a response that has a content type header but no body.

Any advice on how to proceed?

ogrigas commented 6 years ago

I tested that setting response.type("") successfully removes the header in Spark versions 2.6.0 and 2.7.0 and 2.7.1. In only stopped working in version 2.7.2. So as a workaround I reverted to version 2.7.1 for now.

mroloux commented 6 years ago

Thanks for the suggestion. I remained on 2.5.5 for now, but I hope a future Spark version will allow sending responses without a content type again.

bverbeken commented 6 years ago

Any news on this? Can't upgrade to the new and shiny 2.8.0 because of this 😞

andredasilvapinto commented 6 years ago

Same problem here. It would be great to have a fix for this.