Commits

jwhitlock  committed f9506cc

parse_form_data ignores missing CONTENT_TYPE or CONTENT_LENGTH now.

  • Participants
  • Parent commits bb5189c

Comments (0)

Files changed (2)

File tests/test_utils.py

     raises(ArgumentValidationError,
            validate_arguments, take_none, (), {'a': 1}, drop_extra=False)
 
+def test_parse_form_data_put_without_content():
+    '''A PUT without a Content-Type header returns empty data
+
+    Both rfc1945 and rfc2616 (1.0 and 1.1) say "Any HTTP/[1.0/1.1] message
+    containing an entity-body SHOULD include a Content-Type header field
+    defining the media type of that body."  In the case where either
+    headers are omitted, parse_form_data should still work.
+    '''
+    env = create_environ('/foo', 'http://example.org/')
+    del env['CONTENT_TYPE']
+    del env['CONTENT_LENGTH']
+
+    stream, form, files = parse_form_data(env)
+    assert stream.read() == ""
+    assert len(form) == 0
+    assert len(files) == 0
+
 
 def test_header_set_duplication_bug():
     headers = Headers([

File werkzeug/utils.py

         fp=environ['wsgi.input'],
         environ={
             'REQUEST_METHOD':           environ['REQUEST_METHOD'],
-            'CONTENT_TYPE':             environ['CONTENT_TYPE'],
-            'CONTENT_LENGTH':           environ['CONTENT_LENGTH'],
+            'CONTENT_TYPE':             environ.get('CONTENT_TYPE',''),
+            'CONTENT_LENGTH':           environ.get('CONTENT_LENGTH',''),
             'werkzeug.stream_factory':  stream_factory
         },
         keep_blank_values=True