Set chunked Transfer-Encoding when using send

Previously, using `.send()` on `Request` would require to set either the
Transfer-Encoding or the Content-Length header.

In an effort to provide better ergonomics for this library and to avoid
making users fall in a not-so obvious pitfall, the library should build a
valid Request without asking the user to mess around with the headers.

This commit attempts to fix this issue: if the user use `.send()` to
provide an unknown sized reader, the chunked Transfer-Encoding will be
used. Of course, there are prior checks to ensure we do not override the
user wish, like if the user already set a Content-Length or a
Transfer-Encoding.

This commit fix an edge case where the Content-Length would not be
automatically set if the Transfer-Encoding is set but not chunked.
This commit is contained in:
Deluvi
2020-06-23 20:42:10 +02:00
committed by Martin Algesten
parent db0c6fb1b0
commit e224a6d126
4 changed files with 21 additions and 9 deletions

View File

@@ -47,7 +47,7 @@
//! which follows a build pattern. The builders are finished using:
//!
//! * [`.call()`](struct.Request.html#method.call) without a request body.
//! * [`.send()`](struct.Request.html#method.send) with a request body as `Read` (chunked encoding).
//! * [`.send()`](struct.Request.html#method.send) with a request body as `Read` (chunked encoding support for non-known sized readers).
//! * [`.send_string()`](struct.Request.html#method.send_string) body as string.
//! * [`.send_bytes()`](struct.Request.html#method.send_bytes) body as bytes.
//! * [`.send_form()`](struct.Request.html#method.send_form) key-value pairs as application/x-www-form-urlencoded.