diff --git a/sanic/request.py b/sanic/request.py index 82fc64db..8023fd9c 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -32,7 +32,7 @@ class RequestParameters(dict): return self.super.get(name, default) -class Request: +class Request(dict): """ Properties of an HTTP request such as URL, headers, etc. """ diff --git a/tests/test_request_data.py b/tests/test_request_data.py new file mode 100644 index 00000000..098878e7 --- /dev/null +++ b/tests/test_request_data.py @@ -0,0 +1,24 @@ +from sanic import Sanic +from sanic.response import json +from sanic.utils import sanic_endpoint_test +from ujson import loads + + +def test_storage(): + app = Sanic('test_text') + + @app.middleware('request') + def store(request): + request['user'] = 'sanic' + request['sidekick'] = 'tails' + del request['sidekick'] + + @app.route('/') + def handler(request): + return json({ 'user': request.get('user'), 'sidekick': request.get('sidekick') }) + + request, response = sanic_endpoint_test(app) + + response_json = loads(response.text) + assert response_json['user'] == 'sanic' + assert response_json.get('sidekick') is None