[Zope] setHeader, but no getHeader

Mark McEahern mark@mceahern.com
Fri, 31 Jan 2003 12:20:46 -0600


[Lennart Regebro [mailto:lennart@regebro.nu]]
> Because you typically know what you have set the header to, so a getHeader
> isn't really that useful. It would be interesting to know what
> case you have where it would be.

Here's a case:

# this happens first
cache_control_header = 'Cache-Control'
no_cache = 'no-cache'
cache_it = 'max-age=3600'
response.setHeader(cache_control_header, no_cache)

# this happens elsewhere, later
if not response.headers.has_key(cache_control_header):
    response.setHeader(cache_control_header, cache_it)

Because the search via has_key uses the original name of the header, it
fails.

It's painfully obvious now, that I should either:

1) Use literal=1 when calling setHeader if I plan to test for the header
later using the same value.
2) Do a case insensitive search for headers when testing for them.

My point, I guess, is that setHeader()'s default for literal=0 IMHO violates
the principle of Least Surprise.

Cheers,

// m

-