1

How should HttpServletResponse.setHeader method do with null value as below:

response.setHeader("ETag", null);

While implementing Servlet interface, I am a little bit confused on this because the Java Servlet Specification looks not clear about this.

I think I can choose one of these:

  1. Consider null as emptry string "". Set ETag header's value to "".
  2. Do nothing.
  3. Throw an exception.

In practice, Tomcat's implementation just ignore. And netty, even if it is not a Servlet implmentation, throws NullPointerException.

npcode
  • 1,370
  • 1
  • 14
  • 29

1 Answers1

0

According to W3C spec, the ETag values must be double quoted. You can either choose "do nothing" option, or add spec-conformed entity tag header

ETag: "some-etag-value"
Erhan Bagdemir
  • 5,231
  • 6
  • 34
  • 40
  • Yes, it is a correct behavior of HTTP Server for ETag header. But I think setHeader method doesn't need to consider about which header is set. What I want to know is the correct behavior of setHeader method which obeys Java Servlet Specification. – npcode Jul 30 '13 at 10:06