How do delete a HTTP response header?

后端 未结 4 953
庸人自扰
庸人自扰 2020-11-29 01:52

I have a situation where one of the response headers Content-Disposition has to be removed. So I thought of writing a servlet filter to do this. But I realized

4条回答
  •  无人及你
    2020-11-29 02:26

    This may not be Servlet API compliant, but setting the value to null works on GlassFish 4 and probably on Tomcat too as that is what is underneath GlassFish.

    We really need to update the Servlet API specification to either add a method to allow removing headers or to officially support using setHeader with a null value.

    An example where this is important is if you use a security constraint (SSL/TLS) on your web application then static resource caching is complicated by the fact that the container will automatically add headers to prevent caching (you can try to disable with disableProxyCaching and securePagesWithPragma on Tomcat/GlassFish). I've already got a servlet filter for cache control that works great for non-secure content so I would like to keep cache control all in one place and simply set Prama and Cache-Control to null to clear any container added headers.

提交回复
热议问题