Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core


Commits:
6f3b10c8 by Prateek Nayak at 2019-03-21T21:46:33Z
Check request.content_type for None

- - - - -
fc0c88be by Abhilash Raj at 2019-03-21T21:46:33Z
Merge branch 'master' into 'master'

Check request.content_type for None

Closes #569

See merge request mailman/mailman!479
- - - - -


3 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/rest/helpers.py
- src/mailman/rest/tests/test_helpers.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -27,6 +27,7 @@ REST
 * REST API errors are now always formatted as JSON. (See !451)
 * Failed request validations now return more verbose errors, like ``Enum`` 
types
   return all acceptable values. (See !451)     
+* REST API accepts request with content type None (See !479)
 
 
 Command line


=====================================
src/mailman/rest/helpers.py
=====================================
@@ -355,7 +355,8 @@ def get_request_params(request):
     # We parse the request based on the content type. Falcon has a default
     # JSONHandler handler to parse json media type, so we can just do
     # `request.media` to return the request params passed as json body.
-    if request.content_type.startswith('application/json'):
+    if (request.content_type and
+            request.content_type.startswith('application/json')):
         return request.media or dict()
     # request.params returns the parameters passed as URL form encoded.
     return request.params or dict()


=====================================
src/mailman/rest/tests/test_helpers.py
=====================================
@@ -27,6 +27,12 @@ from mailman.rest import helpers
 from mailman.testing.layers import ConfigLayer, RESTLayer
 
 
+class FakeRequest:
+    def __init__(self):
+        self.content_type = None
+        self.params = 'not set'
+
+
 class FakeResponse:
     def __init__(self):
         self.body = 'not set'
@@ -162,6 +168,11 @@ class TestHelpers(unittest.TestCase):
                          {'title': '403 Forbidden',
                           'description': 'Conflicting request', })
 
+    def test_get_request_params_with_none(self):
+        request = FakeRequest()
+        self.assertEqual(helpers.get_request_params(request),
+                         'not set')
+
 
 class TestJSONEncoder(unittest.TestCase):
     """Test the JSON ExtendedEncoder."""



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/de15b8167245a71797d694990d3053472e25e150...fc0c88be08d364c07e73a5a3d3534d2e8037a957

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/de15b8167245a71797d694990d3053472e25e150...fc0c88be08d364c07e73a5a3d3534d2e8037a957
You're receiving this email because of your account on gitlab.com.


_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to