mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Handle multiple transfer-encoding
This commit is contained in:
parent
bd8670b4db
commit
f74324bd75
@ -118,3 +118,11 @@ class ForbiddenProxyRequest(ParseException):
|
|||||||
class InvalidSchemeHeaders(ParseException):
|
class InvalidSchemeHeaders(ParseException):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Contradictory scheme headers"
|
return "Contradictory scheme headers"
|
||||||
|
|
||||||
|
|
||||||
|
class UnsupportedTransferEncoding(ParseException):
|
||||||
|
def __init__(self, te):
|
||||||
|
self.te = te
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "Unsupported Transfer-Encoding: %s" % self.te
|
||||||
|
|||||||
@ -12,7 +12,7 @@ from gunicorn.http.unreader import SocketUnreader
|
|||||||
from gunicorn.http.body import ChunkedReader, LengthReader, EOFReader, Body
|
from gunicorn.http.body import ChunkedReader, LengthReader, EOFReader, Body
|
||||||
from gunicorn.http.errors import (InvalidHeader, InvalidHeaderName, NoMoreData,
|
from gunicorn.http.errors import (InvalidHeader, InvalidHeaderName, NoMoreData,
|
||||||
InvalidRequestLine, InvalidRequestMethod, InvalidHTTPVersion,
|
InvalidRequestLine, InvalidRequestMethod, InvalidHTTPVersion,
|
||||||
LimitRequestLine, LimitRequestHeaders)
|
LimitRequestLine, LimitRequestHeaders, UnsupportedTransferEncoding)
|
||||||
from gunicorn.http.errors import InvalidProxyLine, ForbiddenProxyRequest
|
from gunicorn.http.errors import InvalidProxyLine, ForbiddenProxyRequest
|
||||||
from gunicorn.http.errors import InvalidSchemeHeaders
|
from gunicorn.http.errors import InvalidSchemeHeaders
|
||||||
from gunicorn.util import bytes_to_str, split_request_uri
|
from gunicorn.util import bytes_to_str, split_request_uri
|
||||||
@ -135,7 +135,13 @@ class Message(object):
|
|||||||
raise InvalidHeader("CONTENT-LENGTH", req=self)
|
raise InvalidHeader("CONTENT-LENGTH", req=self)
|
||||||
content_length = value
|
content_length = value
|
||||||
elif name == "TRANSFER-ENCODING":
|
elif name == "TRANSFER-ENCODING":
|
||||||
chunked = value.lower() == "chunked"
|
normalized_value = value.lower()
|
||||||
|
if normalized_value == "identity":
|
||||||
|
pass
|
||||||
|
elif normalized_value == "chunked":
|
||||||
|
chunked = True
|
||||||
|
else:
|
||||||
|
raise UnsupportedTransferEncoding(normalized_value)
|
||||||
elif name == "SEC-WEBSOCKET-KEY1":
|
elif name == "SEC-WEBSOCKET-KEY1":
|
||||||
content_length = 8
|
content_length = 8
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,7 @@ from gunicorn.http.errors import (
|
|||||||
InvalidProxyLine, InvalidRequestLine,
|
InvalidProxyLine, InvalidRequestLine,
|
||||||
InvalidRequestMethod, InvalidSchemeHeaders,
|
InvalidRequestMethod, InvalidSchemeHeaders,
|
||||||
LimitRequestHeaders, LimitRequestLine,
|
LimitRequestHeaders, LimitRequestLine,
|
||||||
|
UnsupportedTransferEncoding
|
||||||
)
|
)
|
||||||
from gunicorn.http.wsgi import Response, default_environ
|
from gunicorn.http.wsgi import Response, default_environ
|
||||||
from gunicorn.reloader import reloader_engines
|
from gunicorn.reloader import reloader_engines
|
||||||
@ -206,7 +207,7 @@ class Worker(object):
|
|||||||
LimitRequestLine, LimitRequestHeaders,
|
LimitRequestLine, LimitRequestHeaders,
|
||||||
InvalidProxyLine, ForbiddenProxyRequest,
|
InvalidProxyLine, ForbiddenProxyRequest,
|
||||||
InvalidSchemeHeaders,
|
InvalidSchemeHeaders,
|
||||||
SSLError)):
|
SSLError, UnsupportedTransferEncoding)):
|
||||||
|
|
||||||
status_int = 400
|
status_int = 400
|
||||||
reason = "Bad Request"
|
reason = "Bad Request"
|
||||||
@ -237,6 +238,10 @@ class Worker(object):
|
|||||||
reason = "Forbidden"
|
reason = "Forbidden"
|
||||||
mesg = "'%s'" % str(exc)
|
mesg = "'%s'" % str(exc)
|
||||||
status_int = 403
|
status_int = 403
|
||||||
|
elif isinstance(exc, UnsupportedTransferEncoding):
|
||||||
|
reason = "Not implemented"
|
||||||
|
mesg = "'%s'" % str(exc)
|
||||||
|
status_int = 501
|
||||||
|
|
||||||
msg = "Invalid request from ip={ip}: {error}"
|
msg = "Invalid request from ip={ip}: {error}"
|
||||||
self.log.debug(msg.format(ip=addr[0], error=str(exc)))
|
self.log.debug(msg.format(ip=addr[0], error=str(exc)))
|
||||||
|
|||||||
5
tests/requests/invalid/022.http
Normal file
5
tests/requests/invalid/022.http
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
GET /stuff/here?foo=bar HTTP/1.1\r\n
|
||||||
|
Transfer-Encoding: chunked\r\n
|
||||||
|
Transfer-Encoding: compress\r\n
|
||||||
|
\r\n
|
||||||
|
xyz
|
||||||
5
tests/requests/invalid/022.py
Normal file
5
tests/requests/invalid/022.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from gunicorn.config import Config
|
||||||
|
from gunicorn.http.errors import UnsupportedTransferEncoding
|
||||||
|
|
||||||
|
cfg = Config()
|
||||||
|
request = UnsupportedTransferEncoding
|
||||||
7
tests/requests/valid/029.http
Normal file
7
tests/requests/valid/029.http
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
GET /stuff/here?foo=bar HTTP/1.1\r\n
|
||||||
|
Transfer-Encoding: chunked\r\n
|
||||||
|
Transfer-Encoding: identity\r\n
|
||||||
|
\r\n
|
||||||
|
5\r\n
|
||||||
|
hello\r\n
|
||||||
|
000\r\n
|
||||||
14
tests/requests/valid/029.py
Normal file
14
tests/requests/valid/029.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from gunicorn.config import Config
|
||||||
|
|
||||||
|
cfg = Config()
|
||||||
|
|
||||||
|
request = {
|
||||||
|
"method": "GET",
|
||||||
|
"uri": uri("/stuff/here?foo=bar"),
|
||||||
|
"version": (1, 1),
|
||||||
|
"headers": [
|
||||||
|
('TRANSFER-ENCODING', 'chunked'),
|
||||||
|
('TRANSFER-ENCODING', 'identity')
|
||||||
|
],
|
||||||
|
"body": b"hello"
|
||||||
|
}
|
||||||
7
tests/requests/valid/030.http
Normal file
7
tests/requests/valid/030.http
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
GET /stuff/here?foo=bar HTTP/1.1\r\n
|
||||||
|
Transfer-Encoding: identity\r\n
|
||||||
|
Transfer-Encoding: chunked\r\n
|
||||||
|
\r\n
|
||||||
|
5\r\n
|
||||||
|
hello\r\n
|
||||||
|
000\r\n
|
||||||
14
tests/requests/valid/030.py
Normal file
14
tests/requests/valid/030.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from gunicorn.config import Config
|
||||||
|
|
||||||
|
cfg = Config()
|
||||||
|
|
||||||
|
request = {
|
||||||
|
"method": "GET",
|
||||||
|
"uri": uri("/stuff/here?foo=bar"),
|
||||||
|
"version": (1, 1),
|
||||||
|
"headers": [
|
||||||
|
('TRANSFER-ENCODING', 'identity'),
|
||||||
|
('TRANSFER-ENCODING', 'chunked')
|
||||||
|
],
|
||||||
|
"body": b"hello"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user