Created
November 23, 2019 20:48
-
-
Save Sytten/91a29b554afc51ca232b823f41022a83 to your computer and use it in GitHub Desktop.
Snipped from gunicorn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def set_body_reader(self): | |
chunked = False | |
content_length = None | |
for (name, value) in self.headers: | |
if name == "CONTENT-LENGTH": | |
content_length = value | |
elif name == "TRANSFER-ENCODING": | |
chunked = value.lower() == "chunked" | |
elif name == "SEC-WEBSOCKET-KEY1": | |
content_length = 8 | |
if chunked: | |
self.body = Body(ChunkedReader(self, self.unreader)) | |
elif content_length is not None: | |
try: | |
content_length = int(content_length) | |
except ValueError: | |
raise InvalidHeader("CONTENT-LENGTH", req=self) | |
if content_length < 0: | |
raise InvalidHeader("CONTENT-LENGTH", req=self) | |
self.body = Body(LengthReader(self.unreader, content_length)) | |
else: | |
self.body = Body(EOFReader(self.unreader)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment