diff options
| author | Julien Danjou <julien@danjou.info> | 2014-12-26 11:33:33 +0100 |
|---|---|---|
| committer | Julien Danjou <julien@danjou.info> | 2014-12-26 14:24:39 +0100 |
| commit | b4ebafde6ac14badb8fc95fc93090003f2d41ccb (patch) | |
| tree | c5752d30e842ebd1b751eb9b3d27d40cd0ee1802 | |
| parent | d396a514a22761103b7fdb05994ac7eb2eb75e36 (diff) | |
| download | webob-b4ebafde6ac14badb8fc95fc93090003f2d41ccb.tar.gz | |
request: read body from file if the method is PATCH
Currently Request.from_file ignore the body of a request if the method
is PATCH. This fixes that by using the dictionary we have to know if a
request might have a body or not.
| -rw-r--r-- | tests/test_request.py | 17 | ||||
| -rw-r--r-- | webob/request.py | 4 |
2 files changed, 19 insertions, 2 deletions
diff --git a/tests/test_request.py b/tests/test_request.py index 24c7aa0..ebe5daf 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -2865,6 +2865,14 @@ class TestRequest_functional(unittest.TestCase): ) self.assertRaises(ValueError, cls.from_file, val_file) + def test_from_file_patch(self): + cls = self._getTargetClass() + req = cls.from_bytes(_test_req_patch) + self.assertEqual("PATCH", req.method) + self.assertTrue(len(req.body)) + self.assertTrue(req.body in _test_req_patch) + self.assertEqual(_test_req_patch, req.as_bytes()) + def test_from_bytes(self): # A valid request without a Content-Length header should still read # the full body. @@ -3563,6 +3571,14 @@ these are the contents of the file 'bar.txt' ------------------------------deb95b63e42a-- """ +_test_req_patch = b""" +PATCH /webob/ HTTP/1.1 +Content-Length: 14 +Content-Type: application/json + +{"foo": "bar"} +""" + _test_req2 = b""" POST / HTTP/1.0 Content-Length: 0 @@ -3606,6 +3622,7 @@ Content-Disposition: form-data; name=file; filename="photo.jpg" _test_req = _norm_req(_test_req) +_test_req_patch = _norm_req(_test_req_patch) _test_req2 = _norm_req(_test_req2) + b'\r\n' _test_req_multipart_charset = _norm_req(_test_req_multipart_charset) diff --git a/webob/request.py b/webob/request.py index c38cf3c..a24f6bf 100644 --- a/webob/request.py +++ b/webob/request.py @@ -1146,7 +1146,7 @@ class BaseRequest(object): # acquire body before we handle headers so that # content-length will be set body = None - if self.method in ('PUT', 'POST'): + if http_method_probably_has_body.get(self.method): if skip_body > 1: if len(self.body) > skip_body: body = bytes_('<body skipped (len=%s)>' % len(self.body)) @@ -1248,7 +1248,7 @@ class BaseRequest(object): if hname in r.headers: hval = r.headers[hname] + ', ' + hval r.headers[hname] = hval - if r.method in ('PUT', 'POST'): + if http_method_probably_has_body.get(r.method): clen = r.content_length if clen is None: body = fp.read() |
