Accept a custom reason phrase for the HTTP response (Fixes #25)

This commit is contained in:
Miguel Grinberg
2021-08-11 10:28:09 +01:00
parent 5cd3ace516
commit bd74bcab74
4 changed files with 50 additions and 5 deletions

View File

@@ -74,9 +74,10 @@ class Response(BaseResponse):
self.complete()
# status code
reason = self.reason if self.reason is not None else \
('OK' if self.status_code == 200 else 'N/A')
await stream.awrite('HTTP/1.0 {status_code} {reason}\r\n'.format(
status_code=self.status_code,
reason='OK' if self.status_code == 200 else 'N/A').encode())
status_code=self.status_code, reason=reason).encode())
# headers
for header, value in self.headers.items():