Added shared request data

This commit is contained in:
Channel Cat 2016-11-19 17:48:28 -08:00
parent 3a1ef6bef2
commit a97e554f8f
2 changed files with 25 additions and 1 deletions

View File

@ -26,7 +26,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.
"""

View File

@ -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['a'] = 'test'
request['b'] = 'zest'
del request['b']
@app.route('/')
def handler(request):
return json({ 'a': request.get('a'), 'b': request.get('b') })
request, response = sanic_endpoint_test(app)
response_json = loads(response.text)
assert response_json['a'] == 'test'
assert response_json.get('b') is None