Commit Graph

720 Commits

Author SHA1 Message Date
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
Michael Richardson
d75643b478 added comment about why socket always returns None 2022-01-31 09:33:38 +01:00
Michael Richardson
034981f535 added example of using mbedtls as a TLS provider
make authentication mode a parameter, default to Required
2022-01-31 09:33:38 +01:00
Malloc Voidstar
ff0e91d33e Fix rustls version spec
">=0.20.1" doesn't have an upper bound and will accept 0.21 (and higher) once they're available.
"0.20.1" means "^0.20.1", which means ">=0.20.1, <0.21".

https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#caret-requirements
2022-01-31 09:16:39 +01:00
Martin Algesten
2c29cc230c Remove Sync requirement of ReadWrite trait
3rd party TLS connections are currently required to provide a Sync
guarantee. Since ureq will only ever use the connection on a single
thread, this is not necessary.

The reason we end up with this bound is because we want Response and
Error to be Sync, in which case Rust's automatic inferral of Sync
fails.

This change "masks" the Stream in a wrapper making it Sync.

Close #474
2022-01-30 21:50:11 +01:00
Martin Algesten
219b5edf9e Rename test function as_write_vec -> into_written_bytes
Tests use `Response::as_write_vec` to inspect the outgoing HTTP/1.1
request line and headers. The current version has two problems:

1. Called `as_write_vec` when it actually returns a `&[u8]`.
2. Inspects/uses the `Response::stream` without consuming `Response`.

The first problem is trivial, but the second is subtle. Currently all
calls on `Response` that works with the internal `Response::stream`
consumes `self` (`into_string`, `into_reader`).

`Response` is by itself `Send + Sync`, and must be so because the
nested Stream is `Read + Write + Send + Sync`. However for
implementors of `TLSStream`, it would be nice to relax the `Sync`
requirement.

Assumption: If all fields in Response are `Sync` except
`Response::stream`, but any access to `stream` consumes `Response`, we
can consider the entire `Response` `Sync`.

This assumption can help us relax the `TlsStream` `Sync` requirement
in a later PR.
2022-01-29 17:32:18 +01:00
Martin Algesten
6e5041044b Rename trait HttpsStream -> ReadWrite and make it public
Also provide an example of how to use it.
2022-01-22 10:41:22 +01:00
Daniel
140aa5901f Add tcp no_delay option (#465)
* Add tcp no_delay option
2022-01-06 23:22:33 +01:00
Martin Algesten
007ce44ea7 Bump version to 2.4.0 2021-12-23 08:38:00 +01:00
Martin Algesten
adbd9144af Update changelog for 2.4.0 2021-12-23 08:38:00 +01:00
Martin Algesten
3b68dce23a Make Middleware always Send + Sync + 'static 2021-12-22 07:58:45 +01:00
Martin Algesten
81c0e66ec7 MiddlewareNext iterator without Box
Thanks @jsha for showing me the way.
2021-12-22 07:58:45 +01:00
Martin Algesten
43680335dc Middleware chain based on iterator 2021-12-22 07:58:45 +01:00
Martin Algesten
a2d62368f3 Remove Option wrapper around middleware 2021-12-22 07:58:45 +01:00
Martin Algesten
09ecb6ffd6 Implement middleware function 2021-12-22 07:58:45 +01:00
Martin Algesten
7b2f28bbc2 Tidy up Response::url initialization 2021-12-22 07:58:45 +01:00