Commit Graph

719 Commits

Author SHA1 Message Date
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
15be014e05 Un-deprecate read/write timeouts. (#78)
In https://github.com/algesten/ureq/pull/67#issuecomment-647112883,
Shnatsel points out that there are uses for read_timeout vs timeout. For
instance, when downloading a large file it's useful to have a read
timouet in case the download stalls, but it would be hard to pick a good
overall timeout without knowing the size of the file and the bandwidth
of the connection.
2020-06-21 14:13:22 -07:00
Jacob Hoffman-Andrews
fdc1f37662 Update documentation. (#73)
* Update documentation.

Synchronize goals section between README and rustdoc, and add two goals
(blocking API; no unsafe) that were mentioned elsewhere in the README.

Add error handling to examples for the module and for the Response
object.

And a section on synthetic errors to the top-level module documentation.

* Add back missing close brace.

* Add main function that returns Result.

* Add links to send_bytes and send_form.

* Document chunked encoding for send.

* Use a larger vec of bytes for send.
2020-06-21 09:55:50 +02:00
Jacob Hoffman-Andrews
7adbd57308 Fix up cargo test --no-default-features. (#75)
Adds some feature guards, and removes an unnecessary feature guard
around a call to connect_https (there's an implementation available for
non-TLS that returns UnknownScheme).

Also, remove unnecessary agent.state() method that was only available in
TLS builds. The state field is directly accessible within the crate, and
can be used in both TLS and non-TLS builds.

Co-authored-by: Martin Algesten <martin@algesten.se>
2020-06-21 09:54:03 +02:00
Jacob Hoffman-Andrews
e366c8fcd0 Remove compile error on native-tls / tls conflict. (#74)
The docs.rs build uses the --all-features flag, which causes its
documentation builds to fail when this macro is present.

Fixes #71.
2020-06-21 09:51:46 +02:00
Jacob Hoffman-Andrews
57be414d97 Add overall timeout for requests. (#67)
This deprecates timeout_read() and timeout_write() in favor of
timeout(). The new timeout method on Request takes a Duration instead
of a number of milliseconds, and is measured against overall request
time, not per-read time.

Once a request is started, the timeout is turned into a deadline
specific to that call. The deadline is used in conjunction with the
new DeadlineStream class, which sets a timeout on each read according
to the remaining time for the request. Once the request is done,
the DeadlineStream is unwrapped via .into::<Stream>() to become
an undecorated Stream again for return to the pool. Timeouts on the
stream are unset at this point.

Still to be done:

Add a setting on Agent for default timeout.
Change header-writing code to apply overall deadline rather than
per-write timeout.
Fixes #28.
2020-06-21 09:47:35 +02:00
Tshepang Lekhonkhobe
d6b712f56f Update README.md
typo
2020-06-19 11:07:09 +02:00
Jacob Hoffman-Andrews
bc2cb57e64 Increase chunked_transfer dependency 2020-06-16 10:04:52 +02:00
Drake Tetreault
e6cbad660d Add Read bound to allow into_inner to be used. 2020-06-16 10:04:52 +02:00
Drake Tetreault
069775d3e0 Use From instead of custom ReclaimStream. 2020-06-16 10:04:52 +02:00
Drake Tetreault
af6491cd59 Remove unsafe usage by taking advantage of new Decoder::unwrap function. 2020-06-16 10:02:57 +02:00
Martin Algesten
787b11b1e4 1.2.0 2020-06-15 09:38:50 +02:00
Martin Algesten
89593d28b3 comment about native-tls 2020-06-15 09:37:10 +02:00
Martin Algesten
7a73fa1871 cargo fmt 2020-06-15 09:33:08 +02:00
k3d3
b79383bbb4 Remove extra line added when merging causing a doc test error 2020-06-15 09:25:49 +02:00
k3d3
efd60e95e9 Change 599 to 500 for TLS errors 2020-06-15 09:25:49 +02:00
k3d3
de3416e260 Fix cfg for test
Fix up cfg attributes to work on an xor basis.

Previously, the cfg(any()) attributes would cause issues when
both native-tls and tls features were enabled. Now, https functions
and enum variants will only be created when tls xor native-tls are
enabled. Additionally, a compile error has been added for when
both tls and native-tls features are enabled.
2020-06-15 09:25:49 +02:00
k3d3
9f7f712dde Add optional native-tls support, clear up warnings for flag configurations 2020-06-15 09:25:49 +02:00
Jacob Hoffman-Andrews
8a05241eac Move test server into its own function 2020-06-15 09:15:36 +02:00
Jacob Hoffman-Andrews
c1d7dbcfe9 Remove no-longer needed feature=tls 2020-06-15 09:15:36 +02:00
Jacob Hoffman-Andrews
64ef337c0b Fix connection_reuse test.
This test was making requests to a server on the Internet. That has the
potential to make the test flaky. Also, the test was relying on a
specific behavior from that server (timing out after 2s), which it no
longer exhibits.

This sets up a local test server that exhibits the specific properties
needed for this test.
2020-06-15 09:15:36 +02:00
Jacob Hoffman-Andrews
378ef57636 Fix findings from cargo clippy. 2020-06-15 09:11:43 +02:00
Jacob Hoffman-Andrews
b4c15eef2c Check for server closed connections.
This builds on 753d61b. Before we send a request, we can do a 1-byte
nonblocking peek on the connection. If the server has closed the
connection, this will give us an EOF, and we can take the connection out
of the pool before sending any request on it. This will reduce the
likelihood that we send a non-retryable POST on an already-closed
connection.

The server could still potentially close the connection between when we
make this check and when we finish sending the request, but this should
handle the majority of cases.
2020-06-15 09:11:25 +02:00
Martin Algesten
0b6323df44 1.1.2 2020-06-12 22:01:02 +02:00
Martin Algesten
deb2002f6f port in host header. close #63 2020-06-12 22:00:30 +02:00
Martin Algesten
4196eeff40 remove curlies warnings 2020-06-12 21:03:49 +02:00
Martin Algesten
c5bc27260b code format 2020-05-23 09:29:57 +02:00
Martin Algesten
aa3e9b1ecf ensure overall connect timeout 2020-05-23 09:28:16 +02:00
Martin Algesten
f03995a72f 1.1.1 2020-05-23 08:57:50 +02:00
David Wolinsky
1842a00da5 Try all sock_addrs before erroring on connect
If DNS resolves to multiple IPs but the service is only running on one
of them and it isn't teh first IP, a connection will fail.

This was detected via running vault that would only bind to IPv4 but
localhost was returning ::1 followed by 127.0.0.1.

After this fix, the service connects without problem.
2020-05-23 08:56:33 +02:00
Martin Algesten
8c1068d40d 1.1.0 2020-05-20 21:29:20 +02:00
Martin Algesten
c281307659 fix test warning 2020-05-20 21:25:47 +02:00
Martin Algesten
1e93f17a58 fix test problem 2020-05-20 21:22:35 +02:00
Rob Young
b61991d87e Fix a couple of feature flag uses
Wrap a json doc-test in cfg block to stop in failing when tests are
run with --no-default-features
2020-05-20 20:55:19 +02:00
Paolo Barbolini
71a9df17e3 Correctly pass --all-features flag to docs.rs 2020-05-20 20:54:43 +02:00
Rob Young
2e3a75166d Allow TLS client config to be overridden
See: https://docs.rs/rustls/latest/rustls/struct.ClientConfig.html
2020-05-20 20:54:04 +02:00
Martin Algesten
bbfd125025 1.0.0 2020-05-06 13:57:01 +02:00
Martin Algesten
49b6072921 cargo fmt 2020-05-06 13:48:52 +02:00
Paolo Barbolini
4e744f87c1 Keep the old Response::into_json around and call this Response::into_json_deserialize 2020-05-06 13:47:37 +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
sklv
8f2d094cef SOCKS5: If host is domain use proxy for DNS. 2020-04-18 11:47:50 +02:00
Koga Kazuo
9f4a7acacb Add set_cookie test 2020-04-18 11:47:49 +02:00
Martin Algesten
a75d924f96 fix some warnings by moving imports around 2020-04-18 11:47:49 +02:00
bbx0
8c2d035809 Clean up dependencies 2020-04-18 11:47:49 +02:00
bbx0
55f42a614b Use &str instead of AsRef<str> to be consistent with the API 2020-04-18 11:47:49 +02:00
bbx0
3bedf9ab69 Add support for application/x-www-form-urlencoded 2020-04-18 11:47:49 +02:00
sklv
92b4e7ec2c Add TODO for supporting timeouts in Socks5Proxy. 2020-04-18 11:47:47 +02:00
sklv
a598b1091b Add comment explaining thread::spawn timeout. 2020-04-18 11:47:44 +02:00
sklv
b0898ae8fd Add comment explaining Proxy::new argument format. 2020-04-18 11:47:40 +02:00
sklv
9928559067 Make SOCKS5 connection respect timeout_connect. 2020-04-18 11:47:37 +02:00