Spark:删除内容类型标题

问题描述:

我试图删除spark中的Content-Type标题。这似乎是不可能的,因为当我尝试使用typeheader方法将其设置为null时。它只是默认为text/htmlSpark:删除内容类型标题

+0

如果您尝试禁用它的静态文件,可以在启动服务器之前禁用mime类型猜测:Service.ignite()。staticFiles.disableMimeTypeGuessing();' – rsommerard

+0

我想为常规路由做。 – Philippe

要删除标题中的Content-Type值,请使用空字符串response.type("")设置响应类型。

这里,在星火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命令输出(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 

[email protected]