Chunked Transfer Encoding in Python Web Applications
Chunked Transfer Encoding is a method introduced in HTTP 1.1 for sending data as a series of successive chunks. The
Content-Length header is not set, therefore nor the sender nor the receiver need to know the size of the entire request beforehand. This allows the sender to start transmitting without buffering the entire request in-memory.
To tell the server that the request is being sent in chunks, the client sets the
Transfer-Encoding: chunked header. The size of the chunk is then sent in the body alongside the chunk divided by a line separator, so the body of a request would look something like this.
7 Chunked 7 Message
In the above example, the size of each chunk is 7 bytes, with one character accounting for one byte.
Reading Chunked Requests
As chunked transfer is not part of the WSGI specification, dealing with such requests is quite tricky. For example: Flask reports the...
Continue reading →