Commit Graph

127 Commits

Author SHA1 Message Date
Ulrik Mikaelsson
f599828c6d Turn Option<AgentState> into AgentState (#149)
`Some(AgentState)` seem to be assumed pretty much everywhere. I could not
find any test or piece of code hinting at how `None` should be interpreted,
or even see how a state of `None` could even be constructed.

Co-authored-by: Ulrik <ulrikm@spotify.com>
2020-09-18 13:47:11 -07:00
Jacob Hoffman-Andrews
c343587afb Use #[cfg(feature = "cookie")] for some functions.
Some helper functions introduced as part of the cookies_on_redirect
test are only used by that test, which means they are only used when the
cookie feature is enabled. This causes clippy warnings for some of the
other feature combinations in CI.
2020-09-14 08:58:02 +02:00
Jacob Hoffman-Andrews
f38c203215 Fix cookies_on_redirect unittest.
Previously this test relied on a specific ordering of cookies, which was
not guaranteed. This makes the test robust to random ordering.

Also, fix the check for the `second` cookie to actually check the right
cookie.
2020-09-13 21:14:40 +02:00
Jacob Hoffman-Andrews
99cdff7519 Add unittest for cookie handling on redirects. 2020-09-13 14:12:17 +02:00
Martin Algesten
a198ba0a65 Test case for preserving io::Error timed out 2020-08-07 21:51:35 +02:00
Martin Algesten
db4cc90956 Normalize timeout ErrorKind::WouldBlock to be TimedOut (#131)
`set_read_timeout` and `set_write_timeout` can cause `ErrorKind::WouldBlock` on unix-y platforms.

This PR normalizes those cases to `ErrorKind::TimedOut`. This will make it simpler higher up in the
stack to deal with timeouts.
2020-08-07 10:06:56 -07:00
Jacob Hoffman-Andrews
7fce93d1c8 Fix tests. 2020-07-02 23:07:53 -07:00
Jacob Hoffman-Andrews
b47f90e773 Factor out TestServer. (#98)
This creates a struct that encapsulates the test server setup, and adds
a shutdown method to clean up the thread when done.
2020-06-30 19:16:34 -07:00
Jacob Hoffman-Andrews
3014f58a28 Add scheme to PoolKey and let port be None. (#84)
PoolKey calls unwrap() on an option that can be None. Specifically, the
local variable `port` can be None when PoolKey is constructed with a Url
whose scheme is unrecognized in url.port_or_known_default().

To fix that, make port an Option. Also, make scheme part of the PoolKey.
This prevents, for instance, a stream opened for `https://example.com:9999`
being reused on a request for `http://example.com:9999`.

Remove the test-only pool.get() accessor. This was used in only one test,
agent_pool in range.rs. This seemed like it was testing the agent more
than it was testing ranges, so I moved it to agent.rs and edited to
remove the range-testing parts.

Also, reject unrecognized URLs earlier in connect_socket so they don't
reach try_get_connection.
2020-06-22 23:23:39 -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
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
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
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
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
1e93f17a58 fix test problem 2020-05-20 21:22:35 +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
Rob Young
28bdb89175 Set a default content type for JSON requests
When sending a JSON request a Content-Type of application/json is
usually wanted. This is often set as a default for JSON methods by HTTP
clients so can be confusing when it is not set. However, we do not want
to prevent the user from setting their own Content-Type.
2020-02-06 07:57:00 +01:00
Tom Forbes
594340a096 Fix compilation errors with the cookies feature (#22)
* Fix compilation errors with the cookies feature
2019-10-30 11:51:06 +01: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
999653e7f3 handle header with spaces before value 2019-10-20 10:58:16 +02:00
Martin Algesten
ed999b579d Removing AsciiString dep and one unsafe
This library is not about enforcing standards, so the internal use of
AsciiString for headers and status lines is not necessary.
2019-10-20 10:40:30 +02:00
Chris West (Faux)
a97dfcb408 fix warnings 2019-09-09 19:54:45 +01:00
Martin Algesten
9d069b60b4 fix tests 2019-06-21 15:53:23 +02:00
Martin Algesten
41b21d37e4 fix clippy warnings 2019-06-21 15:09:36 +02:00
Chris West (Faux)
ceb7c3ac14 use pub(crate) instead of include!() 2019-05-27 17:44:14 +01:00
Martin Algesten
d4d68ae585 fix parse error when no status text. close #4 2019-03-30 11:29:53 +01:00
Martin Algesten
22e83fc31c fixes for no-default-features 2019-02-03 12:05:27 +05:30
Martin Algesten
cb3d6e8124 resolved url in response 2018-12-20 11:08:39 +01:00
Martin Algesten
07fd4d2cd5 pub(crate) where we can 2018-12-20 11:08:20 +01:00
Martin Algesten
1519dcb0b1 fix redirect logic 2018-12-20 10:54:47 +01:00
Martin Algesten
131476bd1a remove extern crate 2018-12-18 13:45:13 +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
8b2d4c0545 test bad headers 2018-07-02 09:23:30 +02:00
Martin Algesten
8decd8e489 auth url test 2018-07-01 18:40:49 +02:00
Martin Algesten
2d2daf58ba doc 2018-07-01 11:13:21 +02:00
Martin Algesten
a14e75fcbc dont require agent().build() 2018-07-01 10:24:42 +02:00
Martin Algesten
567a19a656 resp.status() return u16 2018-07-01 09:04:50 +02:00
Martin Algesten
548b5d80c2 test poolable against s3 2018-06-30 23:05:40 +02:00
Martin Algesten
651c1102c9 better test 2018-06-30 19:30:32 +02:00
Martin Algesten
4a5944443f connection pooling 2018-06-30 16:52:54 +02:00
Martin Algesten
0e4c326caf tidy 2018-06-30 14:01:13 +02:00
Martin Algesten
ff582b8c6f separate out stream 2018-06-30 13:47:37 +02:00
Martin Algesten
b54f747d16 separate out response 2018-06-30 13:36:41 +02:00
Martin Algesten
f5a4c83819 refactor into unit 2018-06-30 13:05:36 +02:00