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:
@@ -210,8 +210,10 @@ impl Request {
|
||||
|
||||
/// Send data from a reader.
|
||||
///
|
||||
/// This uses [chunked transfer encoding](https://tools.ietf.org/html/rfc7230#section-4.1).
|
||||
/// The caller is responsible for setting the Transfer-Encoding: chunked header.
|
||||
/// If no Content-Length and Transfer-Encoding header has been set, it uses the [chunked transfer encoding](https://tools.ietf.org/html/rfc7230#section-4.1).
|
||||
///
|
||||
/// The caller may set the Content-Length header to the expected byte size of the reader if is
|
||||
/// known.
|
||||
///
|
||||
/// The input from the reader is buffered into chunks of size 16,384, the max size of a TLS fragment.
|
||||
///
|
||||
@@ -222,7 +224,6 @@ impl Request {
|
||||
///
|
||||
/// let resp = ureq::post("http://localhost/example-upload")
|
||||
/// .set("Content-Type", "text/plain")
|
||||
/// .set("Transfer-Encoding", "chunked")
|
||||
/// .send(read);
|
||||
/// ```
|
||||
pub fn send(&mut self, reader: impl Read + 'static) -> Response {
|
||||
|
||||
Reference in New Issue
Block a user