From ddf5e66ac864c62d5426d96247f9156a18134597 Mon Sep 17 00:00:00 2001 From: Emile Fugulin Date: Wed, 20 Nov 2019 12:24:52 -0500 Subject: [PATCH] Remove strict check of Transfer-Encoding --- gunicorn/http/errors.py | 8 -------- gunicorn/http/message.py | 9 ++------- gunicorn/workers/base.py | 7 +------ tests/requests/invalid/022.http | 5 ----- tests/requests/invalid/022.py | 5 ----- 5 files changed, 3 insertions(+), 31 deletions(-) delete mode 100644 tests/requests/invalid/022.http delete mode 100644 tests/requests/invalid/022.py diff --git a/gunicorn/http/errors.py b/gunicorn/http/errors.py index ea5b4826..7839ef05 100644 --- a/gunicorn/http/errors.py +++ b/gunicorn/http/errors.py @@ -118,11 +118,3 @@ class ForbiddenProxyRequest(ParseException): class InvalidSchemeHeaders(ParseException): def __str__(self): return "Contradictory scheme headers" - - -class UnsupportedTransferEncoding(ParseException): - def __init__(self, te): - self.te = te - - def __str__(self): - return "Unsupported Transfer-Encoding: %s" % self.te diff --git a/gunicorn/http/message.py b/gunicorn/http/message.py index 59f50d7e..e5ce4a68 100644 --- a/gunicorn/http/message.py +++ b/gunicorn/http/message.py @@ -12,7 +12,7 @@ from gunicorn.http.unreader import SocketUnreader from gunicorn.http.body import ChunkedReader, LengthReader, EOFReader, Body from gunicorn.http.errors import (InvalidHeader, InvalidHeaderName, NoMoreData, InvalidRequestLine, InvalidRequestMethod, InvalidHTTPVersion, - LimitRequestLine, LimitRequestHeaders, UnsupportedTransferEncoding) + LimitRequestLine, LimitRequestHeaders) from gunicorn.http.errors import InvalidProxyLine, ForbiddenProxyRequest from gunicorn.http.errors import InvalidSchemeHeaders from gunicorn.util import bytes_to_str, split_request_uri @@ -135,13 +135,8 @@ class Message(object): raise InvalidHeader("CONTENT-LENGTH", req=self) content_length = value elif name == "TRANSFER-ENCODING": - normalized_value = value.lower() - if normalized_value == "identity": - pass - elif normalized_value == "chunked": + if value.lower() == "chunked": chunked = True - else: - raise UnsupportedTransferEncoding(normalized_value) elif name == "SEC-WEBSOCKET-KEY1": content_length = 8 diff --git a/gunicorn/workers/base.py b/gunicorn/workers/base.py index 7689c61f..f95994bc 100644 --- a/gunicorn/workers/base.py +++ b/gunicorn/workers/base.py @@ -20,7 +20,6 @@ from gunicorn.http.errors import ( InvalidProxyLine, InvalidRequestLine, InvalidRequestMethod, InvalidSchemeHeaders, LimitRequestHeaders, LimitRequestLine, - UnsupportedTransferEncoding ) from gunicorn.http.wsgi import Response, default_environ from gunicorn.reloader import reloader_engines @@ -207,7 +206,7 @@ class Worker(object): LimitRequestLine, LimitRequestHeaders, InvalidProxyLine, ForbiddenProxyRequest, InvalidSchemeHeaders, - SSLError, UnsupportedTransferEncoding)): + SSLError)): status_int = 400 reason = "Bad Request" @@ -238,10 +237,6 @@ class Worker(object): reason = "Forbidden" mesg = "'%s'" % str(exc) status_int = 403 - elif isinstance(exc, UnsupportedTransferEncoding): - reason = "Not implemented" - mesg = "'%s'" % str(exc) - status_int = 501 msg = "Invalid request from ip={ip}: {error}" self.log.debug(msg.format(ip=addr[0], error=str(exc))) diff --git a/tests/requests/invalid/022.http b/tests/requests/invalid/022.http deleted file mode 100644 index 784504be..00000000 --- a/tests/requests/invalid/022.http +++ /dev/null @@ -1,5 +0,0 @@ -GET /stuff/here?foo=bar HTTP/1.1\r\n -Transfer-Encoding: chunked\r\n -Transfer-Encoding: compress\r\n -\r\n -xyz diff --git a/tests/requests/invalid/022.py b/tests/requests/invalid/022.py deleted file mode 100644 index db5c9f38..00000000 --- a/tests/requests/invalid/022.py +++ /dev/null @@ -1,5 +0,0 @@ -from gunicorn.config import Config -from gunicorn.http.errors import UnsupportedTransferEncoding - -cfg = Config() -request = UnsupportedTransferEncoding