[PATCH] Allow unsetting headers previously set by header()
| From: | Christian Schmidt | Date: | Thu, 27 Mar 2008 22:32:05 +0000 |
| Subject: | [PATCH] Allow unsetting headers previously set by header() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-36631@lists.php.net to get a copy of this message | ||
When a header has been set using header('Foo: bar') it can be replaced with
other headers, but it cannot be removed.
For instance, one could imagine that the auto_prepend_file calls
header('Vary: Accept-Language') because most pages do language-negotiation.
But if a single file generates, say, an image, it would improve caching if
the Vary header was removed. Setting it to the empty string using
header('Vary:') is not equivalent to unsetting the header.
I suggest extending the behaviour of header() so that when the first
argument does not contain a colon (and does not begin with "HTTP/"), e.g.
header('Vary'), it unsets the header with the specified name.
AFAICT this change is backwards compatible. According to the HTTP spec, RFC
2616, section 4.2, header lines must include a colon, so calling e.g.
header('Vary') does currently not generate a valid header:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
The attached patch contains an implementation for the cgi and apache2handler
SAPIs.
AFAICT these SAPIs don't need to be changed:
cli, embed, isapi, milter, pi3web, thttpd, tux, webjames.
These SAPIs need additional patching:
apache, apache_hooks, apache2filter, continuity/capi, caudium, nsapi,
phttpd, roxen
I don't have an easy way to test these SAPIs, so any help with adding
support for them is appreciated. AFAICT some of these don't have full
header() support (in particular for the second $replace parameter), so it
may not be a big issue if they aren't patched right away.
For some reason I couldn't build apache2filter on my machine.
The atteched phpt file is intended to be put in
ext/standard/tests/general_functions.
What do you think of the general idea of being able to unset headers?
And what do you think of my patch?
This is my first patch for PHP. I am not a strong C programmer.
Christian