[Python-checkins] python/dist/src/Lib urllib2.py,1.42,1.43

Guido van Rossum guido@python.org
Mon, 12 May 2003 17:53:02 -0400


> Skip Montanaro wrote:
> >     bcannon> Change Request.add_header to call string.capitalize in order to
> >     bcannon> normalize headers and not have any dependency on case.  Closes
> >     bcannon> patch #649742.
> > 
> >     bcannon> !         self.headers[key.capitalize()] = val
> > 
> > Maybe use key.title() instead?
> > 
> >     >>> "content-type".capitalize()
> >     'Content-type'
> >     >>> "content-type".title()
> >     'Content-Type'
> > 
> 
> So the original reason of doing 'capitalize' is because farther down in 
> urllib2 there is a check to see if "Content-type" is set and it is 
> specifically in that case.  It really is a judgment call since the RFC 
> doesn't even keep the case consistent.
> 
> So moving to 'title' would be fine but the lines in urllib2.py that 
> check for the existence of 'Content-type' and 'Content-length' would 
> need to be changed.

But if the headers object were truly case-insensitive this wouldn't be
necessary.  I think anything short of a case-insensitive directory is
brittle here...

--Guido van Rossum (home page: http://www.python.org/~guido/)