Repository: falconry/falcon

Issue:
Rename Request.body to Request.stream
Mirros Response. And it really is a stream.



Discussion:
Don't forget to update the example code in the README


Resolving patch:
diff --git a/falcon/request.py b/falcon/request.py
--- a/falcon/request.py
+++ b/falcon/request.py
@@ -32,13 +32,13 @@ class Request(object):
 
     __slots__ = (
         'app',
-        'body',
         '_headers',
         'method',
         '_params',
         'path',
         'protocol',
         'query_string',
+        'stream',
         '_wsgierrors'
     )
 
@@ -54,7 +54,7 @@ def __init__(self, env):
         """
 
         self._wsgierrors = env['wsgi.errors']
-        self.body = env['wsgi.input']
+        self.stream = env['wsgi.input']
 
         self.protocol = env['wsgi.url_scheme']
         self.app = env['SCRIPT_NAME']


Test patch:
diff --git a/tests/test_example.py b/tests/test_example.py
--- a/tests/test_example.py
+++ b/tests/test_example.py
@@ -14,8 +14,7 @@ def __init__(self, db):
         self.db = db
         self.logger = logging.getLogger('thingsapi.' + __name__)
 
-    def on_get(self, req, resp):
-        user_id = req.get_param('user_id', required=True)
+    def on_get(self, req, resp, user_id):
         marker = req.get_param('marker', default='')
         limit = req.get_param('limit', default=50)
 
@@ -42,15 +41,15 @@ def on_get(self, req, resp):
             raise falcon.HTTPUnsupportedMediaType(
                 'Media Type not Supported',
                 'This API only supports the JSON media type.',
-                'http://docs.example.com/json')
+                'http://docs.examples.com/api/json')
 
         try:
             result = self.db.get_things(marker, limit)
         except Exception as ex:
             self.logger.error(ex)
 
-            description = ('Aliens have attacked our base. We will be back '
-                           'as soon as we fight them off. We appreciate your '
+            description = ('Aliens have attacked our base. We will be back'
+                           'as soon as we fight them off. We appreciate your'
                            'patience.')
 
             raise falcon.HTTPServiceUnavailable('Service Outage', description)
@@ -61,7 +60,7 @@ def on_get(self, req, resp):
 
     def on_post(self, req, resp):
         try:
-            raw_json = req.body.read()
+            raw_json = req.stream.read()
         except Exception:
             raise falcon.HTTPError(falcon.HTTP_748,
                                    'Read Error',
diff --git a/tests/test_request_body.py b/tests/test_request_body.py
--- a/tests/test_request_body.py
+++ b/tests/test_request_body.py
@@ -9,7 +9,7 @@ def prepare(self):
 
     def test_empty_body(self):
         self._simulate_request('/', body='')
-        stream = self.resource.req.body
+        stream = self.resource.req.stream
 
         stream.seek(0, 2)
         self.assertEquals(stream.tell(), 0)
@@ -17,7 +17,7 @@ def test_empty_body(self):
     def test_tiny_body(self):
         expected_body = '.'
         self._simulate_request('', body=expected_body)
-        stream = self.resource.req.body
+        stream = self.resource.req.stream
 
         actual_body = stream.read(1)
         self.assertEquals(actual_body, expected_body.encode('utf-8'))
@@ -35,7 +35,7 @@ def test_read_body(self):
         content_len = self.resource.req.get_header('content-length')
         self.assertEqual(content_len, str(expected_len))
 
-        stream = self.resource.req.body
+        stream = self.resource.req.stream
 
         actual_body = stream.read()
         self.assertEquals(actual_body, expected_body.encode('utf-8'))