Why does lib/python/ZPublisher/HTTPResponse.py have a setHeader(), but not a getHeader()? Seeing how setHeader() converts the header name to lowercase, it would make sense to have a getHeader() that converts the queried key to lower before searching self.headers. [Oops, but then what about the literal flag?] Hmm, maybe HTTPResponse.py is assuming everyone reads the relevant RFCs? ;-) Cheers, // m -
get_header() is a method of the REQUEST object and of course not of the RESPONSE object. -aj --On Freitag, 31. Januar 2003 09:15 -0600 Mark McEahern <mark@mceahern.com> wrote:
Why does lib/python/ZPublisher/HTTPResponse.py have a setHeader(), but not a getHeader()?
Seeing how setHeader() converts the header name to lowercase, it would make sense to have a getHeader() that converts the queried key to lower before searching self.headers. [Oops, but then what about the literal flag?]
Hmm, maybe HTTPResponse.py is assuming everyone reads the relevant RFCs? ;-)
Cheers,
// m
-
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
--------------------------------------------------------------------- - Andreas Jung http://www.andreas-jung.com - - EMail: andreas at andreas-jung.com - - "Life is too short to (re)write parsers" - ---------------------------------------------------------------------
[Andreas Jung [mailto:lists@andreas-jung.com]]
get_header() is a method of the REQUEST object and of course not of the RESPONSE object.
So suppose I use response.setHeader() and then, later somewhere else during the processing of the request/response, I want to check whether that header is set. I'm not sure I understand how the REQUEST.get_header() is relevant? Thanks, // mark -
--On Freitag, 31. Januar 2003 10:21 -0600 Mark McEahern <mark@mceahern.com> wrote:
[Andreas Jung [mailto:lists@andreas-jung.com]]
get_header() is a method of the REQUEST object and of course not of the RESPONSE object.
So suppose I use response.setHeader() and then, later somewhere else during the processing of the request/response, I want to check whether that header is set. I'm not sure I understand how the REQUEST.get_header() is relevant?
If you really need to look at the headers of the RESPONSE object then sniff into its header attribute. A get_header() method is IMO a clear case of YAGNI. -aj
[Andreas Jung [mailto:lists@andreas-jung.com]]
If you really need to look at the headers of the RESPONSE object then sniff into its header attribute. A get_header() method is IMO a clear case of YAGNI.
Yes, I'm not having a problem looking at the headers. However, what I'm saying is that the API of HTTPResponse is potentially confusing. Why convert some names to lowercase, only later to convert them to word capitalization unless literal is specified? If the HTTP RFC says header names are case-insensitive, why not just use a case-insensitive dictionary and be done with it? If you want to talk YAGNI, then wouldn't that apply to setHeader() as well? My question is not about how to use HTTPResponse. I've already gone through the painful process of learning that (or so I think, anyway <wink>). I'm trying to have a conversation about why it is the way it is and whether there's some way to reduce the learning curve for folks in the future. Thanks, // m -
From: "Mark McEahern" <mark@mceahern.com>
Why does lib/python/ZPublisher/HTTPResponse.py have a setHeader(), but not a getHeader()?
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.
[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 -
participants (3)
-
Andreas Jung -
Lennart Regebro -
Mark McEahern