[Python-bugs-list] The Python 1.5.2 cgi module doesn't handle PUT requests properly

Jim Fulton jim@digicool.com
Tue, 01 Jun 1999 16:10:35 -0400


This is a multi-part message in MIME format.
--------------7C92C4AFE09F003C6019498C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


The cgi module in Python 1.5.2 sets the content-type to 
application/x-www-form-urlencoded when no content-type header is
provided.  This is an error.  It is legal for HTTP requests to
ommit this header and most (or at least the most widely used ;)
clients don't include a content type in PUT requests, which are 
used by many publishing tools.

I've attached a context diff that fixes this problem.

Jim

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org    

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.
--------------7C92C4AFE09F003C6019498C
Content-Type: text/plain; charset=us-ascii;
 name="t"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="t"

diff -c /projects/python/src/Python-1.5.2/Lib/cgi.py cgi.py
*** /projects/python/src/Python-1.5.2/Lib/cgi.py	Fri Jan  8 12:42:03 1999
--- cgi.py	Tue Jun  1 16:04:25 1999
***************
*** 841,850 ****
          # but it happens to be something we don't understand.
          if self.headers.has_key('content-type'):
              ctype, pdict = parse_header(self.headers['content-type'])
-         elif self.outerboundary:
-             ctype, pdict = "text/plain", {}
          else:
!             ctype, pdict = 'application/x-www-form-urlencoded', {}
          self.type = ctype
          self.type_options = pdict
          self.innerboundary = ""
--- 841,848 ----
          # but it happens to be something we don't understand.
          if self.headers.has_key('content-type'):
              ctype, pdict = parse_header(self.headers['content-type'])
          else:
!             ctype, pdict = "text/plain", {}
          self.type = ctype
          self.type_options = pdict
          self.innerboundary = ""
***************
*** 867,873 ****
              self.read_urlencoded()
          elif ctype[:10] == 'multipart/':
              self.read_multi(environ, keep_blank_values, strict_parsing)
!         elif self.outerboundary:
              # we're in an inner part, but the content-type wasn't something we 
              # understood.  default to read_single() because the resulting
              # FieldStorage won't be a mapping (and doesn't need to be).
--- 865,872 ----
              self.read_urlencoded()
          elif ctype[:10] == 'multipart/':
              self.read_multi(environ, keep_blank_values, strict_parsing)
!         elif (self.outerboundary or
!               ctype!= 'application/x-www-form-urlencoded'):
              # we're in an inner part, but the content-type wasn't something we 
              # understood.  default to read_single() because the resulting
              # FieldStorage won't be a mapping (and doesn't need to be).

--------------7C92C4AFE09F003C6019498C--