Spark: Remove Content-Type header

1k Views Asked by At

I'm trying to remove the Content-Type header in spark. It seems to be impossible as when I try to set it to null using the type or header methods. It just defaults to text/html.

1

There are 1 best solutions below

1
On BEST ANSWER

To remove the Content-Type value in the header, set the response type with an empty String response.type("").

Here, an example of code that works on Spark v2.6.0:

public class Main {
    public static void main(String[] args) {
        get("/hello", new Route() {
            @Override
            public Object handle(Request request, Response response) throws Exception {
                response.type("");
                response.body("hello world");
                return response;
            }
        });
    }
}

Httpie command output (http 0.0.0.0:4567/hello):

HTTP/1.1 200 OK
Date: Mon, 14 Aug 2017 19:12:17 GMT
Server: Jetty(9.4.4.v20170414)
Transfer-Encoding: chunked

spark.Response@592d7509