From 8abba597a8cf136b6597e69e905c014e13f761eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=2E=20K=C3=A4rkk=C3=A4inen?= <98187+Tronic@users.noreply.github.com> Date: Sun, 26 Apr 2020 06:18:59 +0300 Subject: [PATCH] Do not set content-type and content-length headers in exceptions. (#1820) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: L. Kärkkäinen --- sanic/exceptions.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/sanic/exceptions.py b/sanic/exceptions.py index 6ce93698..000b9e76 100644 --- a/sanic/exceptions.py +++ b/sanic/exceptions.py @@ -45,10 +45,7 @@ class InvalidUsage(SanicException): class MethodNotSupported(SanicException): def __init__(self, message, method, allowed_methods): super().__init__(message) - self.headers = dict() - self.headers["Allow"] = ", ".join(allowed_methods) - if method in ["HEAD", "PATCH", "PUT", "DELETE"]: - self.headers["Content-Length"] = 0 + self.headers = {"Allow": ", ".join(allowed_methods)} @add_status_code(500) @@ -101,10 +98,7 @@ class HeaderNotFound(InvalidUsage): class ContentRangeError(SanicException): def __init__(self, message, content_range): super().__init__(message) - self.headers = { - "Content-Type": "text/plain", - "Content-Range": "bytes */%s" % (content_range.total,), - } + self.headers = {"Content-Range": f"bytes */{content_range.total}"} @add_status_code(417)