Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clone web request's state #2287

Merged
merged 1 commit into from
Sep 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix #2284: Clone web request's state
asvetlov committed Sep 23, 2017

Verified

This commit was signed with the committer’s verified signature. The key has expired.
juliusknorr Julius Knorr
commit 4dd162193fa200c92fa3b6d7e3317fe6a956bad7
10 changes: 7 additions & 3 deletions aiohttp/web_request.py
Original file line number Diff line number Diff line change
@@ -62,7 +62,10 @@ class BaseRequest(collections.MutableMapping, HeadersMixin):

def __init__(self, message, payload, protocol, writer, time_service, task,
loop,
*, secure_proxy_ssl_header=None, client_max_size=1024**2):
*, secure_proxy_ssl_header=None, client_max_size=1024**2,
state=None):
if state is None:
state = {}
self._message = message
self._protocol = protocol
self._transport = protocol.transport
@@ -78,7 +81,7 @@ def __init__(self, message, payload, protocol, writer, time_service, task,

self._secure_proxy_ssl_header = secure_proxy_ssl_header
self._time_service = time_service
self._state = {}
self._state = state
self._cache = {}
self._task = task
self._client_max_size = client_max_size
@@ -120,7 +123,8 @@ def clone(self, *, method=sentinel, rel_url=sentinel,
self._time_service,
self._task,
self._loop,
secure_proxy_ssl_header=self._secure_proxy_ssl_header)
secure_proxy_ssl_header=self._secure_proxy_ssl_header,
state=self._state.copy())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope there are no nested dicts/list in state, right?


@property
def task(self):
1 change: 1 addition & 0 deletions changes/2284.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Properly clone state of web request
9 changes: 9 additions & 0 deletions tests/test_web_request.py
Original file line number Diff line number Diff line change
@@ -620,3 +620,12 @@ def test_remote_peername_forwarded_overrides_x_forwarded():
headers={'Forwarded': 'for=11.11.11.11, for=12.12.12.12',
'X-Forwarded-For': '13.13.13.13'})
assert req.remote == '11.11.11.11'


def test_save_state_on_clone():
req = make_mocked_request('GET', '/')
req['key'] = 'val'
req2 = req.clone()
req2['key'] = 'val2'
assert req['key'] == 'val'
assert req2['key'] == 'val2'