Decode the 'chunked' transfer coding.
(self)
| 498 | environ["CONTENT_LENGTH"] = cl |
| 499 | |
| 500 | def decode_chunked(self): |
| 501 | """Decode the 'chunked' transfer coding.""" |
| 502 | cl = 0 |
| 503 | data = StringIO.StringIO() |
| 504 | while True: |
| 505 | line = self.rfile.readline().strip().split(";", 1) |
| 506 | chunk_size = int(line.pop(0), 16) |
| 507 | if chunk_size <= 0: |
| 508 | break |
| 509 | ## if line: chunk_extension = line[0] |
| 510 | cl += chunk_size |
| 511 | data.write(self.rfile.read(chunk_size)) |
| 512 | crlf = self.rfile.read(2) |
| 513 | if crlf != "\r\n": |
| 514 | self.simple_response("400 Bad Request", |
| 515 | "Bad chunked transfer coding " |
| 516 | "(expected '\\r\\n', got %r)" % crlf) |
| 517 | return |
| 518 | |
| 519 | # Grab any trailer headers |
| 520 | self.read_headers() |
| 521 | |
| 522 | data.seek(0) |
| 523 | self.environ["wsgi.input"] = data |
| 524 | self.environ["CONTENT_LENGTH"] = str(cl) or "" |
| 525 | return True |
| 526 | |
| 527 | def respond(self): |
| 528 | """Call the appropriate WSGI app and write its iterable output.""" |
no test coverage detected