Commit Graph

496 Commits

Author SHA1 Message Date
cazgp
22d815e5e7 Make Cookie header RFC6265 compliant (#130) 2020-08-07 10:04:15 -07:00
André Cruz
75d5e52a45 Added method to set the TLS connection builder (#116)
This allows configuring the accepted certs, client authentication,
etc, when using the native TLS crate.
2020-07-28 21:44:35 +02:00
André Cruz
74afb82de9 Remove brackets from IPv6 literals before passing to TLS connector (#115) 2020-07-13 11:46:28 +02:00
dependabot-preview[bot]
81aab6e79a Update rustls requirement from 0.17 to 0.18 (#112)
Updates the requirements on [rustls](https://github.com/ctz/rustls) to permit the latest version.
- [Release notes](https://github.com/ctz/rustls/releases)
- [Changelog](https://github.com/ctz/rustls/blob/main/OLDCHANGES.md)
- [Commits](https://github.com/ctz/rustls/compare/v/0.17.0...v/0.18.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-07-08 08:43:17 -07:00
dependabot-preview[bot]
06aa1eb63a Update rustls-native-certs requirement from 0.3 to 0.4 (#111)
Updates the requirements on [rustls-native-certs](https://github.com/ctz/rustls-native-certs) to permit the latest version.
- [Release notes](https://github.com/ctz/rustls-native-certs/releases)
- [Commits](https://github.com/ctz/rustls-native-certs/compare/v/0.3.0...v/0.4.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-07-08 08:42:28 -07:00
Alex L
ea3b93dcab Add Proxy field to PoolKey. (#114)
Fixes #109
2020-07-08 08:41:43 -07:00
Jacob Hoffman-Andrews
87b8a381bc Remove default base URL of http://localhost/ (#108)
This doesn't change the API at all, since it delays any errors until do_call.
Since there was already an `Into<Response> for Error`, and do_call already
had a `.unwrap_or_else(|e| e.into())`, nothing in do_call needed to change.
The only visible effect of this is that code that was previously relying on
`get("/path")` to fetch something from localhost will now get an error. I think
most of those cases would probably actually be accidents, possibly caused
by typos, e.g. `get("example.com/path")` (forgetting the https: prefix).

Fixes #105
2020-07-05 14:25:59 -07:00
Jacob Hoffman-Andrews
f16f1a5e47 Error when LimitedRead gets too few bytes. (#106) 2020-07-05 14:25:11 -07:00
Jacob Hoffman-Andrews
7fce93d1c8 Fix tests. 2020-07-02 23:07:53 -07:00
Jacob Hoffman-Andrews
b53de7a7ed Remove default URL_BASE of localhost. 2020-07-02 23:01:51 -07:00
dependabot-preview[bot]
6e69f6cf69 Update cookie requirement from 0.13 to 0.14
Updates the requirements on [cookie](https://github.com/SergioBenitez/cookie-rs) to permit the latest version.
- [Release notes](https://github.com/SergioBenitez/cookie-rs/releases)
- [Changelog](https://github.com/SergioBenitez/cookie-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/SergioBenitez/cookie-rs/compare/0.13.0...0.14.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-01 10:55:27 +02:00
Jacob Hoffman-Andrews
ea7ed88399 Request: rename path field to URL. (#104)
* Request: rename path field to URL.

This more accurately reflects its use.
2020-07-01 09:53:10 +02:00
Jacob Hoffman-Andrews
e4ad3a5e5f Remove unnecessary lifetime annotations. (#103) 2020-07-01 09:40:47 +02:00
Jacob Hoffman-Andrews
bbde617719 Add --no-deps to doc build. (#102) 2020-07-01 09:36:57 +02:00
Jacob Hoffman-Andrews
4d7bf5dcda Validate header field names. (#99)
This rejects spaces after field names as well as various other invalid
characters.

Fixes #96
2020-06-30 19:32:17 -07:00
dependabot-preview[bot]
c9ccbd5f09 Update webpki-roots requirement from 0.19 to 0.20 (#100)
Updates the requirements on [webpki-roots](https://github.com/ctz/webpki-roots) to permit the latest version.
- [Release notes](https://github.com/ctz/webpki-roots/releases)
- [Commits](https://github.com/ctz/webpki-roots/compare/v/0.19.0...v/0.20.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-06-30 19:17:19 -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
dafdf6a718 Tweak README. (#92)
The layout of crates.io means that code blocks overflow after 60
characters, so wrap before 60 to avoid needing a scrollbar.

Remove the warning about the Agent code. I think after our recent
testing, I believe it's good enough that it doesn't need a separate
warning.

Remove the old-style macro-use directive and the extern crate directive.
2020-06-26 19:09:24 +02:00
Jacob Hoffman-Andrews
3f78953874 Add a GitHub action for building docs. (#89)
This helps ensure we don't break that doc build.
2020-06-24 21:20:07 +02:00
Martin Algesten
4e1e3d1ad4 Make features to use for docs.rs build explicit (#90)
Since tls and native-tls are mutually exclusive, we can't use
all-features anymore. Instead we enumerate the features needed to
build the docs for docs.rs.
2020-06-24 09:37:15 -07:00
Martin Algesten
6bb838f205 Fix building with socks-proxy feature (#91)
This PR corrects a variable name and type, and ensures we
test the socks-proxy feature as part of the test matrix.
2020-06-24 09:36:08 -07:00
Jacob Hoffman-Andrews
3cb178ed7c 1.3.0 (#83)
1.3.0
2020-06-24 09:14:00 +02:00
Jacob Hoffman-Andrews
1a40bed7dd Fix reference to Instant in socks feature. (#88)
The reference to time::Instant under feature = socks-proxy was
incorrectly scoped, and should have been just Instant. This breaks the
doc build and any builds that use feature = socks-proxy.
2020-06-24 09:13:12 +02:00
Jacob Hoffman-Andrews
a85f4c037e Remove some panics in deadline checking. (#87)
time_until_deadline had a time of check to time of use problem - the
deadline could pass between a call to checked_duration_since and the
evaluation of `deadline - now` (which panics if the result would be
negative). Resolve that by flipping the order of
checked_duration_since's arguments and using the result rather than
ignoring it.

Also there were three places that called deadline - now(), which could
panic. Replace those with time_until_deadline().
2020-06-23 23:45:18 -07:00
Jacob Hoffman-Andrews
2d6747717d Limit max idle connections. (#81)
Adds limit of 100 connections to ConnectionPool. This is implemented
with a VecDeque acting as an LRU. When the pool becomes full, the oldest
stream is popped off the back from the VecDeque and also removed from
the map of PoolKeys to Streams.

Fixes #77
2020-06-23 23:44:47 -07:00
Jacob Hoffman-Andrews
a6e99c8b36 Add smoke test in examples. (#85)
This loads a list of top domain names (e.g. from
https://tranco-list.eu/) and tries to fetch them all, in parallel. This
can be used to exercise ureq and find panics.
2020-06-23 21:09:09 -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
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