Commit Graph

685 Commits

Author SHA1 Message Date
Nathan Henrie
33fb553a28 Remove references to serde_derive (#581) 2023-01-09 14:46:00 -08:00
Jacob Hoffman-Andrews
032bfb4b27 gzip: examine Content-Length header before removing (#578)
Fixes #575.
2023-01-02 20:02:37 -08:00
Jacob Hoffman-Andrews
78ec3a4d75 Update CHANGELOG for 2.6.0 (#572) 2022-12-30 21:56:23 -08:00
Jacob Hoffman-Andrews
a8ca1ec085 Fix clippy 2022-12-09 17:03:35 +01:00
Jacob Hoffman-Andrews
6bef9daa8e Switch ureq to used forked chunked_transfer. 2022-12-09 17:03:35 +01:00
Jacob Hoffman-Andrews
43a12cdf51 Modify chunked crate for ureq use. 2022-12-09 17:03:35 +01:00
Jacob Hoffman-Andrews
fe3f1d550b Fork chunked_transfer crate 2022-12-09 17:03:35 +01:00
Jacob Hoffman-Andrews
9083d692f8 Redesign pooling mechanic (#565)
Introduce PoolReturner, a handle on an agent and a PoolKey that is
capable of returning a Stream to a Pool. Make Streams keep track of
their own PoolReturner, instead of having PoolReturnRead keep track of
that information.

For the LimitedRead code path, get rid of PoolReturnRead. Instead,
LimitedRead is responsible for returning its Stream to the Pool after
its second-to-last read. In other words, LimitedRead will return the
stream if the next read is guaranteed to return Ok(0).

Constructing a LimitedRead of size 0 is always wrong, because we could
always just return the stream immediately. Change the size argument to
NonZeroUsize to enforce that.

Remove the Done trait, which was only used for LimitedRead. It was used
to try and make sure we returned the stream to the pool on exact reads,
but was not reliable.

This does not yet move the ChunkDecoder code path away from
PoolReturnRead. That requires a little more work.

Part 1 of #559.  Fixes #555.
2022-12-03 23:42:58 -08:00
Jacob Hoffman-Andrews
d8225b22ed Split response body type into own function (#566)
This allows removing the hack where we create a Response with an empty `reader`,
then immediately mutate it to set the real reader. It also happens to allow us
to get rid of 3 fields of Response that were only used to pass information to
`stream_to_reader`.

I've tried to keep the structure and logic of the body calculation as close to
the same as possible, for ease of review and to avoid introducing bugs. I think
there are some followup fixes we can make to the logic, which will be made
easier by having it in a self contained function.
2022-12-03 10:22:53 -08:00
Jacob Hoffman-Andrews
cf687381bd Don't panic when rustls-native-certs errors (#564)
Fixes #563
2022-11-30 22:12:48 -08:00
Martin Algesten
f36c140315 Add gzip and brotli to CI test matrix 2022-11-26 11:46:00 +01:00
Martin Algesten
8e8b1abd53 Upgrade deps 2022-11-26 11:46:00 +01:00
zu1k
614d1dd7bc Make query_pairs more generic
Signed-off-by: zu1k <i@zu1k.com>
2022-11-26 11:09:33 +01:00
zu1k
78998dd032 feat: Set multi query parameters
Signed-off-by: zu1k <i@zu1k.com>
2022-11-26 11:09:33 +01:00
Jacob Hoffman-Andrews
dc7a8c3ebe Config-gate gzip test 2022-11-26 01:44:08 -08:00
Jacob Hoffman-Andrews
3745b028c6 Switch to MultiGzDecoder
This is more correct, since all gzip streams can consist of multiple members. It
has the happy side effect that it causes gzipped responses to reliably return
their streams to the pool.
2022-11-26 01:44:08 -08:00
Martin Algesten
5d9e89917c Test case showing gzip chunk not pooling 2022-11-26 01:44:08 -08:00
Jacob Hoffman-Andrews
a2836c49a7 Fix new clippy lints (#561) 2022-11-26 10:28:36 +01:00
Wolf Thomsen
28d667ade9 add badges to crates.io and docs.rs to README.md (#554) 2022-11-12 21:31:58 +01:00
Max von Forell
855f20e662 Add Response::remote_addr() (#489)
Fixes #488.
2022-10-03 13:29:21 -07:00
Martin Algesten
b0796c18f3 Make build work (#546)
The mbedtls example has caused problem in the main build a number of
times. By making it a standalone `cargo new --bin`, we can keep it in
the source tree as a good example but avoid having it break the main
build.

Also, fix some clippy lints.
2022-09-29 08:29:32 -07:00
Michael Schubart
a367a82317 Fix mistake in API docs 2022-08-28 12:09:17 +02:00
Martin Algesten
134d82ecf4 debug! log method of body response 2022-07-10 11:55:57 +02:00
Martin Algesten
0a202ad90f Updated CHANGELOG for 2.5.0 2022-07-10 11:30:40 +02:00
Martin Algesten
84d58587c0 Bump version to 2.5.0 2022-07-10 11:30:40 +02:00
Jacob Hoffman-Andrews
f14fc45179 Buffer short responses (2) (#531)
* Response: build reader at construction time

* Remove unwrapping/rewrapping DeadlineStream

* Let into_reader() provide Sync + 'static

* Prebuffer Vec use known capacity

Co-authored-by: Martin Algesten <martin@algesten.se>
2022-07-10 11:12:50 +02:00
Jacob Hoffman-Andrews
9908c446d6 Simplify ReadWrite interface (#530)
Previously, ReadWrite had methods `is_poolable` and `written_bytes`, which
were solely for the use of unittests.

This replaces `written_bytes` and `TestStream` with a `struct Recorder`
that implements `ReadWrite` and allows unittests to access its recorded
bytes via an `Arc<Mutex<Vec<u8>>>`. It eliminates `is_poolable`; it's fine
to pool a Stream of any kind.

The new `Recorder` also has some convenience methods that abstract away
boilerplate code from many of our unittests.

I got rid of `Stream::from_vec` and `Stream::from_vec_poolable` because
they depended on `TestStream`. They've been replaced by `NoopStream` for
the pool.rs tests, and `ReadOnlyStream` for constructing `Response`s from
`&str` and some test cases.
2022-07-09 10:13:44 -07:00
Jacob Hoffman-Andrews
0cf1f8dbb9 Add Sync traits to ReadWrite trait (#528)
This allows us to get rid of a Mutex (and not take a dependency on
sync_wrapper).
2022-07-05 01:52:25 -07:00
Martin Algesten
9395046029 IoResult -> io::Result (#521) 2022-06-11 17:06:43 -07:00
guyo13
c94284482a Return Err on deadline checked_add overflow instead of panic (#517) 2022-05-22 19:51:58 +02:00
Jacob Hoffman-Andrews
8a32cae507 Remove sync_wrapper dep in favor of Mutex (#514)
We unwrap the stream exactly once per response, and we know that case
will be uncontended for the same reason `SyncWrapper` works:
`into_reader()` takes `self`, so it must have exclusive ownership.
Uncontended mutexes are extremely cheap. This saves us a dependency
at a trivial performance cost.
2022-05-09 10:32:23 -07:00
Jacob Hoffman-Andrews
4bb6d3a4db DeadlineStream: read from Stream's buffer first (#508)
This fixes an issue where requests with a deadline would do a syscall
on every read, rather than pulling from the buffer. Fixes a problem
reported in #506 where `resp.into_json()` was unnecessarily slow.
2022-05-09 10:31:59 -07:00
Martin Algesten
4675d748e9 Remove Sync bound from TlsConnector io arg 2022-05-07 14:39:59 +02:00
Martin Algesten
049b5a5acd Fixes after feedback 2022-05-07 14:39:59 +02:00
Martin Algesten
65371c966c Box<dyn ReadWrite> for TlsConnector::connect 2022-05-07 14:39:59 +02:00
Jacob Hoffman-Andrews
101467f13f Return stream to pool on exact read (#509)
If the user reads exactly the number of bytes in the response, then
drops the Read object, streams will never get returned to the pool since
the user never triggered a read past the end of the LimitedRead.

This fixes that by making PoolReturnRead aware of the level below it, so
it can ask if a stream is "done" without actually doing a read.

Also, a refactorign:

Previously, Response contained an Option<Box<Unit>> because the testing
method `from_str()` would construct a Response with no associated Unit.
However, this increased code complexity with no corresponding test
benefit. Instead, construct a fake Unit in from_str().

Also, instead of taking an `Option<Box<Unit>>`, PoolReturnRead now takes
a URL (to figure out host and port for the PoolKey) and an &Agent where
it will return the stream. This cuts interconnectedness somewhat:
PoolReturnRead doesn't need to know about Unit anymore.
2022-04-30 17:22:27 -07:00
Jacob Hoffman-Andrews
4d77d365a0 Improve unittest 2022-04-30 14:55:07 +02:00
Jacob Hoffman-Andrews
ec8095be49 Fix Debug impl for AgentConfig
Wrap Arc<dyn TlsConnector> in a newtype with a stub Debug impl so we can
go back to `#[derive(Debug)]` on AgentConfig.
2022-04-30 14:55:07 +02:00
Martin Algesten
653cf03dee Fix and and
Close #503
2022-04-24 19:40:20 +02:00
Martin Algesten
ce13168a96 Run cargo readme 2022-04-22 20:41:40 +02:00
dependabot[bot]
e4f064d4f2 Update rustls-pemfile requirement from 0.3 to 1.0
Updates the requirements on [rustls-pemfile](https://github.com/rustls/pemfile) to permit the latest version.
- [Release notes](https://github.com/rustls/pemfile/releases)
- [Commits](https://github.com/rustls/pemfile/compare/v/0.3.0...v/1.0.0)

---
updated-dependencies:
- dependency-name: rustls-pemfile
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-22 19:26:47 +02:00
Ed Morley
a8ed085a93 Fix broken TLS anchor link in docs overview
Now correctly links to:
https://docs.rs/ureq/latest/ureq/#https--tls--ssl

Introduced in 56276c3742.

Also fixes a rustdoc typo spotted by my IDE's spell checker whilst the
project was open.
2022-04-22 19:25:44 +02:00
Martin Algesten
21238ef2e0 Provide example of more in-depth TLS config
Close #480
2022-04-12 20:43:27 +02:00
Martin Algesten
e225532966 Update cookie dep to 0.16 2022-04-12 20:33:09 +02:00
Pierre Dubouilh
0a71385b29 fix clippy 2022-04-08 09:53:55 +02:00
Pierre Dubouilh
aced0d9b6a implement https_only flag 2022-04-08 09:53:55 +02:00
Joshua Nelson
06743da5de Warn if Requests aren't sent (#490)
I added `ureq::get("http://example.com")` to a toy program and was very confused when it did nothing.
Change `Request` to give a warning if unsent:
```
warning: unused `ureq::Request` that must be used
  --> src/main.rs:48:5
   |
48 |     ureq::get("http://example.com");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_must_use)]` on by default
   = note: Requests do nothing until consumed by `call()`
```
2022-03-16 15:27:10 -07:00
dependabot[bot]
f549184d7f Update rustls-pemfile requirement from 0.2 to 0.3
Updates the requirements on [rustls-pemfile](https://github.com/rustls/pemfile) to permit the latest version.
- [Release notes](https://github.com/rustls/pemfile/releases)
- [Commits](https://github.com/rustls/pemfile/compare/v/0.2.0...v/0.3.0)

---
updated-dependencies:
- dependency-name: rustls-pemfile
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-10 17:25:50 +01:00
Martin Algesten
4f3ea15523 Clean up mbedtls example 2022-01-31 09:45:57 +01:00
Martin Algesten
5dbaa9a256 Rename example mbedtls-req -> mbedtls 2022-01-31 09:45:57 +01:00