diff --git a/aiohttp/web_reqrep.py b/aiohttp/web_reqrep.py index d5c6a3756a9..8fde688b131 100644 --- a/aiohttp/web_reqrep.py +++ b/aiohttp/web_reqrep.py @@ -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 @@ -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(): @@ -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)