Commit Graph

20 Commits

Author SHA1 Message Date
Deluvi
e224a6d126 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.
2020-09-27 10:50:24 +02:00
Jacob Hoffman-Andrews
6a88c2c8bf Clean up unused code and long imports. (#137)
This removes some commented out methods, and also changes instances of
::std::foo to use a more idiomatic import path.
2020-09-12 18:42:15 -07:00
Jacob Hoffman-Andrews
00461fb5bd Only retry idempotent requests. (#80)
This also reverts a change to send_body that was originally added to
return the number of bytes written. It's no longer needed now that we
check the size of the reader in advance.

Fixes #76.
2020-06-22 09:40:55 -07:00
Jacob Hoffman-Andrews
378ef57636 Fix findings from cargo clippy. 2020-06-15 09:11:43 +02:00
Martin Algesten
49b6072921 cargo fmt 2020-05-06 13:48:52 +02:00
Paolo Barbolini
0b69c595b6 Make Response::into_json deserialize into a serde DeserializeOwned
This removes the necessity to take the result of Response::into_json and
having to convert it into a struct by using serde_json::from_value

This adds no new dependencies since serde_json already depends on serde.
Users of ureq will have to include `serde_derive` either by importing it
directly or by using serde with the `derive` feature, unless they want to
manually implement `Deserialize` on their structs.
2020-05-06 13:47:37 +02:00
Nicolas Viennot
652500f5a8 Improve chunked transfer upload performance
This implementation improves over chunked_transfer's Encoder + io::copy
with the following performance optimizations:

1) It avoid copying memory
2) chunked_transfer's Encoder issues 4 separate write() per chunk.
   This is costly overhead. Instead, we do a single write() per chunk

The measured benefit on a Linux machine is a 50% reduction in CPU usage
on a https connection.
2020-04-06 09:15:41 +02:00
Martin Algesten
753d61b454 Retry some pooled connections failing when server closes. Close #10
This is not a perfect solution. It works as long as we are not sending
any body bytes. We discover the error first when attempting to read
the response status line. That means we discover the error after
sending body bytes. To be able to re-send the body, we would need to
introduce a buffer to be able to replay the body on the next
request. We don't currently do that.
2019-10-20 21:36:38 +02:00
Martin Algesten
e936d5ea74 cargo fmt 2019-10-20 10:41:35 +02:00
Martin Algesten
fef05fd5c9 send_bytes 2019-06-21 15:53:45 +02:00
Martin Algesten
07fd4d2cd5 pub(crate) where we can 2018-12-20 11:08:20 +01:00
Martin Algesten
4151aab3b4 redirects 0 2018-12-18 13:34:05 +01:00
Martin Algesten
5ba6b3cd4d edition 2018, clippy, fmt 2018-12-18 13:17:19 +01:00
Martin Algesten
454e5a123f fix send body confusion 2018-07-03 10:54:22 +02:00
Martin Algesten
6d3dc75e73 code format 2018-07-02 09:10:31 +02:00
Martin Algesten
4fbcc2246f doc 2018-07-01 19:01:35 +02:00
Martin Algesten
03928a05c5 tidy up 2018-07-01 10:19:40 +02:00
Martin Algesten
4a5944443f connection pooling 2018-06-30 16:52:54 +02:00
Martin Algesten
924393b811 std::io::copy instead of own 2018-06-30 14:55:58 +02:00
Martin Algesten
54558fbb26 refactor to body 2018-06-30 14:11:54 +02:00