Commit Graph

364 Commits

Author SHA1 Message Date
Jacob Hoffman-Andrews
310c14d601 Update CHANGELOG for 1.5.2. (#216) 2020-11-08 20:40:09 -08:00
Joshua Nelson
acaf449a4c Allow getting the error from a response (#214)
This is an alternative to https://github.com/algesten/ureq/pull/132
which does not require breaking changes.

Closes https://github.com/algesten/ureq/issues/126.
2020-11-08 11:13:03 -08:00
Jacob Hoffman-Andrews
6781122b46 Merge pull request #205 from steffahn/generalize_send_reader_lifetime
Make Request::send more general.
2020-10-25 16:46:13 -07:00
Jacob Hoffman-Andrews
17ab5110a3 Use lifetimes for more elements of Payload
Text and Bytes can both have their lifetimes parameterized.
2020-10-25 15:52:02 -07:00
Frank Steffahn
c8cd130770 Make Request::send more general.
Removes `+ 'static` constraint from the `impl Read` parameter.
For this, lifetime parameters are added to `Payload` and `SizedReader`.
2020-10-25 21:51:04 +01:00
Jacob Hoffman-Andrews
22e3839340 Review feedback. 2020-10-24 12:12:07 +02:00
Jacob Hoffman-Andrews
2bf9362eff Reinstate read timeouts on body.
This feature was broken in #67, which reset timeouts on the
stream before passing it to set_stream.

As part of this change, refactor the internal storage of
timeouts on the Request object to use Option<Duration>.

Remove the deadline field on Response. It wasn't used. The
deadline field on unit was used instead.

Add a unittest.
2020-10-24 12:12:07 +02:00
Jacob Hoffman-Andrews
32f9ebc04a Separate overall_timeout checks. 2020-10-24 12:08:27 +02:00
Jacob Hoffman-Andrews
1f5f65877a Update overall_timeout_during_headers test. 2020-10-24 12:08:27 +02:00
Jacob Hoffman-Andrews
14475cb5c7 Add test for read_timeout during headers. 2020-10-24 12:08:27 +02:00
Jacob Hoffman-Andrews
67c28d28a3 Check for synthetic_error early in unit::connect 2020-10-24 12:08:27 +02:00
dependabot-preview[bot]
bd2761e280 Update env_logger requirement from 0.7.1 to 0.8.1
Updates the requirements on [env_logger](https://github.com/env-logger-rs/env_logger) to permit the latest version.
- [Release notes](https://github.com/env-logger-rs/env_logger/releases)
- [Changelog](https://github.com/env-logger-rs/env_logger/blob/master/CHANGELOG.md)
- [Commits](https://github.com/env-logger-rs/env_logger/compare/v0.7.1...v0.8.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-10-19 09:11:35 +02:00
Jacob Hoffman-Andrews
00e3294ac1 Remove convenience methods for CONNECT verb. (#177)
CONNECT, specified at https://tools.ietf.org/html/rfc7231#section-4.3.6,
says:

> if successful, thereafter restrict its behavior to blind forwarding
> of packets, in both directions, until the tunnel is closed.

ureq doesn't actually support the semantics of CONNECT, since it doesn't
offer a bidirectional channel on a Response. So I'm fairly confident no
one is using these methods.
2020-10-07 22:54:31 -07:00
Martin Algesten
e763446d72 1.5.1 2020-10-06 10:06:36 +02:00
Martin Algesten
95cbb15a68 Changelog for 1.5.1 2020-10-06 10:05:48 +02:00
Jacob Hoffman-Andrews
e3138b0ace Add proxy on agent. (#178) 2020-10-06 00:12:26 -07:00
Jacob Hoffman-Andrews
5b75deccef Use correct host on redirect. (#180) 2020-10-06 00:10:56 -07:00
Jacob Hoffman-Andrews
2d4b42e298 Use cookie_store crate instead of cookie::CookieJar (#169)
CookieJar doesn't support the path-match and domain-match algorithms from [RFC 6265](https://tools.ietf.org/html/rfc6265#section-5.1.3), while cookie_store does.

This fixes some issues with the cookie matching algorithm currently in ureq. For instance,
the domain-match uses substring matching rather than the RFC 6265 algorithm.

This deletes two tests:

match_cookies_returns_nothing_when_no_cookies didn't test much
agent_cookies was failing because cookie_store rejects cookies on the `test:` scheme.
  The way around this is to set up a testserver - but it turns out cookies_on_redirect already
  does that, and covers the same cases and more.

This changes some cookie-related behavior:

 - Cookies could previously be sent to a wrong domain - e.g. a cookie set on `example.com`
  could go to `example.com.evil.com` or `evilexample.com`. Probably no one was relying on
  this, since it's quite broken.
 - A cookie with a path of `/foo` could be sent on a request to `/foobar`, but now it can't.
 - Cookies could previously be set on IP addresses, but now they can't.
 - Cookies could previously be set for domains other than the one on the request (or its
  parents), but now they can't.
 - When a cookie had no domain attribute, it would previously get the domain from the
  request, and subsequently be sent to that domain and all subdomains. Now, it will only
  be sent to that exact domain (host-only).

That last one is probably the most likely to break people, since someone could depend
on it without realizing it was broken behavior.
2020-10-04 10:21:09 -07:00
Martin Algesten
0bf981031b Replace lazy_static! with once_cell Lazy (#176)
Modern rust code bases prefer once_cell::sync::Lazy over the older
macro based lazy_static.
2020-10-04 09:35:31 -07:00
Jacob Hoffman-Andrews
b58a3a53b0 Add test.sh. (#173)
This emulates the test matrix that gets run in CI, making it easier to
find failures locally.

There was one conflict in the matrix: when JSON is enabled and TLS is
disabled, two of the doctests would fail. This was previous worked
around as an exclude in the github workflow. I changed the JSON doctest
to use HTTP instead.
2020-10-03 20:47:35 -07:00
dependabot-preview[bot]
b8d02f9785 Update base64 requirement from 0.12 to 0.13
Updates the requirements on [base64](https://github.com/marshallpierce/rust-base64) to permit the latest version.
- [Release notes](https://github.com/marshallpierce/rust-base64/releases)
- [Changelog](https://github.com/marshallpierce/rust-base64/blob/master/RELEASE-NOTES.md)
- [Commits](https://github.com/marshallpierce/rust-base64/compare/v0.12.0...v0.13.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-10-03 10:44:31 +02:00
Jacob Hoffman-Andrews
d4dfe4096f Feature-gate AgentState 2020-10-01 14:27:59 -07:00
Martin Algesten
573b175cf7 1.5.0 2020-09-29 11:12:00 +02:00
Martin Algesten
0346794e87 Fix bug in force-unwrapping when resetting timers
When running tests locally, this error can surface.

```
---- test::agent_test::custom_resolver stdout ----
thread 'test::agent_test::custom_resolver' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }', src/stream.rs:60:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

The problem is that setting the timeouts might fail, and this is done
in a From trait where there is not possibility to "bubble" the
io::Error.

```
socket.set_read_timeout(None).unwrap();
socket.set_write_timeout(None).unwrap();
```

This commit moves the resetting of timers to an explicit `Stream::reset()` fn
that must be called every time we're unwrapping the inner stream.
2020-09-29 11:10:16 +02:00
Jacob Hoffman-Andrews
6f70349172 Update 1.5.0 changelog. 2020-09-29 11:01:44 +02:00
Jacob Hoffman-Andrews
17d7e147eb Handle ConnectionReset+ConnectionAbort at any time (#168)
Previously we had a special case for BadStatusRead that would happen
only when we got a ConnectionAborted error reading the status line.
However, sometimes we get ConnectionReset instead. Also the HTTP
spec says that idempotent requests may be retried anytime a connection
is closed prematurely.

The change treats as retryable any ConnectionAborted OR ConnectionReset
error while reading the status line and headers. It removes the special
case BadStatusRead error.

Fixes #165 (I think).
2020-09-29 01:55:34 -07:00
Jacob Hoffman-Andrews
06d6435374 Merge branch 'master' of https://github.com/algesten/ureq into cookie_store 2020-09-29 01:45:52 -07:00
Jacob Hoffman-Andrews
9300c50461 Make cookie_store optional 2020-09-29 01:45:26 -07:00
Jacob Hoffman-Andrews
065b560dfb Add log dependency. (#170)
Also add log statements to unit. Each request gets one info line;
retries, redirects, and responses get logged at debug level.
2020-09-29 01:37:39 -07:00
Jacob Hoffman-Andrews
9b39e55d1c Use cookie_store 2020-09-29 00:34:29 -07:00
Jacob Hoffman-Andrews
4b95d4d29e Cookie refactor 2020-09-28 22:41:29 -07:00
Jacob Hoffman-Andrews
995f6e44a9 Pass through io::Errors when reading headers. (#166)
Previously any io::Error on reading a status line or response headers
would be unconditionally mapping into BadStatus or BadHeader. I think
it's better to pass through the actual io::Error.

BadStatusRead is still kept, since it has special status when dealing
with timed out connections, and BadStatus is still used when the status
line is malformed.
2020-09-28 09:14:26 -07:00
Jacob Hoffman-Andrews
e4d2ce8494 Add changelog for 1.5.0. (#164) 2020-09-27 19:50:51 -07:00
Jacob Hoffman-Andrews
264abdf452 Add PRs to changelog. 2020-09-27 11:36:55 -07:00
Jacob Hoffman-Andrews
e4e9455fa8 Add changelog for 1.5.0. 2020-09-27 11:33:11 -07:00
Jacob Hoffman-Andrews
5801f87c56 Remove Sync 2020-09-27 20:24:24 +02:00
Jacob Hoffman-Andrews
5e00b5c5e3 Add Send + Sync marker traits to into_reader.
This allows the resulting Read to be shared among threads.
2020-09-27 20:24:24 +02:00
Jacob Hoffman-Andrews
7046b07518 Replace IoResult and IoError with io:: versions. (#161) 2020-09-27 10:20:24 -07:00
Jacob Hoffman-Andrews
e8c3403f7b Remove DEFAULT_HOST (#153)
In a few places we relied on "localhost" as a default if a URL's host
was not set, but I think it's better to error out in these cases.

In general, there are a few places in Unit that assumed there is a
host as part of the URL. I've made that explicit by doing a check
at the beginning of `connect()`. I've also tried to plumb through
the semantics of "host is always present" by changing the parameter
types of some of the functions that use the hostname.

I considered a more thorough way to express this with types - for
instance implementing an `HttpUrl` struct that embeds a `Url`, and
exports most of the same methods, but guarantees that host is always
present. However, that was more invasive than this so I did a smaller
change to start.
2020-09-27 10:07:13 -07:00
Deluvi
fec79dcef3 Modify Transfer-Encoding behavior to check for last encoding only 2020-09-27 10:50:24 +02:00
Deluvi
7de192d3f1 Add BodySize enum 2020-09-27 10:50:24 +02:00
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
db0c6fb1b0 Print better errors 2020-09-27 10:42:05 +02:00
Jacob Hoffman-Andrews
786047629a bugfix: Don't re-pool streams on drop.
We only want streams in the pool that are ready for the next request,
and don't have any remaining bytes of the previous request. That's the
case when we return a stream due to EOF on the underlying `Read`.

However, there was also an `impl Drop` that returned the stream to the
pool on drop of a PoolReturnRead. That resulted in a bug: If a user
called `response.into_reader()`, but did not read the entire body,
a dirty stream would be returned to the pool. The next time a request
was made to the same host, that stream would be reused, and instead of
reading off "HTTP/1.1 200 OK", ureq would read a remnant of the previous
request, resulting in a BadStatus error.
2020-09-27 10:42:05 +02:00
Jacob Hoffman-Andrews
b01be808c5 Fix set_max_idle_connections(0).
This broke during some recent refactorings. The special case branch for
max_connections == 0 wasn't actually setting the max_idle_connections
field.

This change simply deletes that branch, since the existing code that
whittles down the pool size one element at a time suffices. In the
common case this will be set on an empty pool anyhow.
2020-09-27 10:20:30 +02:00
Ulrik Mikaelsson
11413726cd Implement Pluggable Name-resolution (#148)
This defines a new trait `Resolver`, which turns an address into a
Vec<SocketAddr>. It also provides an implementation of Resolver for
`Fn(&str)` so it's easy to define simple resolvers with a closure.


Fixes #82

Co-authored-by: Ulrik <ulrikm@spotify.com>
2020-09-26 16:35:13 -07:00
Daniel Rivas
8bba07a9af Add req field to Unit and remove cloned parts from request (#158)
Instead of cloning most of `Request`'s fields individually when
creating a `Unit`, this PR switches to just cloning `Request` and
stuffing it in `Unit`, and changes references to `unit.[field]` to
`unit.req.[field]` where appropriate.

Fixes #155
2020-09-26 10:22:10 -07:00
Jacob Hoffman-Andrews
be9e3ca936 Update comment about retries.
This comment previously assumed we would have at most one pooled
connection per host. That's no longer true, so update the comment.
2020-09-21 08:14:28 +02:00
Martin Algesten
155edeef19 cargo fmt (#151) 2020-09-19 00:28:39 -07:00
Jacob Hoffman-Andrews
b87299e988 Document and tidy up new Pool invariants. (#142)
Now that we allow multiple connections for the same PoolKey, update our
invariants accordingly. Also provide a couple of helper functions for
removing the first or last match of an entry in a VecDeque.

This also changes which entry from `lru` gets removed when a stream is
removed from the pool. Previously it was the oldest matching one. Now it's
the newest matching one, which matches the semantics we are applying to
`recycle[K]`.

Followup to #133 

/cc @cfal
2020-09-18 19:35:22 -07:00