2017-08-01 86 views
0

我試圖刪除spark中的Content-Type標題。這似乎是不可能的,因爲當我嘗試使用typeheader方法將其設置爲null時。它只是默認爲text/htmlSpark:刪除內容類型標題

+0

如果您嘗試禁用它的靜態文件,可以在啓動服務器之前禁用mime類型猜測:Service.ignite()。staticFiles.disableMimeTypeGuessing();' – rsommerard

+0

我想爲常規路由做。 – Philippe

回答

1

要刪除標題中的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]