Skip to content

Commit

Permalink
Deprecate changing the status code of a response after it has been pr…
Browse files Browse the repository at this point in the history
…epared
  • Loading branch information
arthurdarcet authored Dec 13, 2016
1 parent 5412d9e commit 2ac27a3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion aiohttp/web_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ def __init__(self, *, status=200, reason=None, headers=None):
self._compression_force = False
self._headers = CIMultiDict()
self._cookies = http.cookies.SimpleCookie()
self.set_status(status, reason)

self._req = None
self._resp_impl = None
Expand All @@ -466,6 +465,8 @@ def __init__(self, *, status=200, reason=None, headers=None):
self._headers.extend(headers)
if hdrs.CONTENT_TYPE not in self._headers:
self._headers[hdrs.CONTENT_TYPE] = 'application/octet-stream'

self.set_status(status, reason)

def _copy_cookies(self):
for cookie in self._cookies.values():
Expand Down Expand Up @@ -498,6 +499,8 @@ def reason(self):
return self._reason

def set_status(self, status, reason=None):
if self.prepared:
warnings.warn('Changing the response status after it has been started is a no-op and will be ignored', DeprecationWarning)
self._status = int(status)
if reason is None:
reason = ResponseImpl.calc_reason(status)
Expand Down

0 comments on commit 2ac27a3

Please sign in to comment.