mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Change base-classes for NoMoreData, ChunkMissingTerminator and InvalidChunkSize.
If remote client send invalid data in request with "Transfer-Encoding:chunked" gunicorn can raised some exceptions (see http.body.ChunkedReader) as NoMoreData, ChunkMissingTerminator, InvalidChunkSize.
User application shouldn't know about specific gunicorn exceptions and must catch standard IOError if want.
Example:
def app(env, start_response):
body = env["wsgi.input"]
chunk_size = 1024
while True:
try:
chunk = body.read(chunk_size)
except IOError:
.. correct action for error
if not chunk:
break
.. do somethink with chunk
This commit is contained in:
parent
4be3282440
commit
75933bae81
@ -6,7 +6,7 @@
|
|||||||
class ParseException(Exception):
|
class ParseException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class NoMoreData(ParseException):
|
class NoMoreData(IOError):
|
||||||
def __init__(self, buf=None):
|
def __init__(self, buf=None):
|
||||||
self.buf = buf
|
self.buf = buf
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@ -49,14 +49,14 @@ class InvalidHeaderName(ParseException):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Invalid HTTP header name: %s" % self.hdr
|
return "Invalid HTTP header name: %s" % self.hdr
|
||||||
|
|
||||||
class InvalidChunkSize(ParseException):
|
class InvalidChunkSize(IOError):
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Invalid chunk size: %r" % self.data
|
return "Invalid chunk size: %r" % self.data
|
||||||
|
|
||||||
class ChunkMissingTerminator(ParseException):
|
class ChunkMissingTerminator(IOError):
|
||||||
def __init__(self, term):
|
def __init__(self, term):
|
||||||
self.term = term
|
self.term = term
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user