tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Lee <dave.lee.wil...@gmail.com>
Subject setHeader with null value
Date Mon, 06 Jun 2005 16:46:19 GMT
Hello all,

In the webapp I work on, we have code that calls
response.setHeader(name, null) to remove headers that have been
previously set.  These are the various browser cache headers.  With
tomcat4 and tomcat5 this works, but with tomcat5.5 this no longer
works, the header is still sent to the client with the original value.

I have looked at the javadocs and the servlet 2.4 spec, and I see no
information on how setHeader(name, value) is expected to behave when
the value is null.  In any case, I think something should be done when
the value is null, currently this method is pretty much a no-op when
the value is null.  Even if a NullPointerException was thrown, at
least then it would raise the issue to the developer.  Given the way
the webapp I am working with is "designed", I figured it would be
easier to "fix" the setHeader implementation to be consistent with
past tomcat releases rather than trying to refactor the logic of my
app so that I don't need to remove previously set headers.

I wanted to email the dev list to get some feedback, particularly,
should I submit a bug report on this?  Even if it's not considered a
true bug, it is a regression issue given the fact that the behaviour
changes from previous tomcats.

Here is a patch (using 5.5.9) to have setHeader(name, null) remove the header.

--- jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Response.java.original
     2005-03-26 13:22:00.000000000 -0700
+++ jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Response.java
  2005-06-05 18:53:38.696176500 -0600
@@ -322,7 +322,12 @@
             if( checkSpecialHeader(name, value) )
             return;
         }
-        headers.setValue(name).setString( value);
+        if (value != null) {
+            headers.setValue(name).setString( value);
+        }
+        else {
+            headers.removeHeader(name);
+        }
     }

Thanks,
Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message