TLS-related options were only being applied for URLs with a `https://`
scheme. But that's too cautious, because we could run into a HTTPS URL
after a redirect.
I've fixed this by just removing the check. Another option is to also
check `args.follow`, but I think it's nicer to do this stuff
unconditionally. That way we can consistently give errors for bad
options (e.g. `--verify=path/wiht/typo`).
Test case:
```shell
xh --verify=no --follow http://httpbin.org/redirect-to url==https://expired.badssl.com
```
Fixes#368.
Add `env_logger` to be able to print the logs that our libraries
already generate.
Add some logging to the application code. We'll probably want more log
messages, and we might want to upgrade some of them from trace to
debug.
Add a `--debug` flag that automatically enables `env_logger` as well
as backtraces for `anyhow` and panics.
```console
$ xh --debug :
[2024-06-05T13:54:40Z DEBUG xh] xh 0.22.0 -native-tls +rustls
[2024-06-05T13:54:40Z DEBUG xh] Cli {
httpie_compat_mode: false,
[...]
}
[2024-06-05T13:54:40Z DEBUG xh] Complete URL: http://localhost/
[2024-06-05T13:54:40Z DEBUG xh] HTTP method: GET
[2024-06-05T13:54:40Z DEBUG reqwest::connect] starting new connection: http://localhost/
[2024-06-05T13:54:40Z DEBUG hyper_util::client::legacy::connect::dns] resolving host="localhost"
[...]
xh: error: error sending request for url (http://localhost/)
Caused by:
0: client error (Connect)
1: tcp connect error: Connection refused (os error 111)
2: Connection refused (os error 111)
Stack backtrace:
0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.82/src/error.rs:565:25
[...]
```
We could ask users to post `--debug` output when reporting bugs.
Environment variables can have no value at all or they can have the
empty string as a value. We used to disable color if `$NO_COLOR` were
set at all, regardless of its value, but as of
99f90e27d0
we should ignore empty strings (and this makes more sense).
Result: `NO_COLOR= xh` now allows colors.
Instead of parsing the JSON input into a complicated heap value before
writing it out we can write it out as we parse it. On a ridiculously
large input this gives me a 5× speedup.
A read operation might get an "interrupted" error, in which case the
correct behavior is (usually) to try again as if nothing happened.
When we read a compressed stream we check whether the underlying
reader received an error. But we should only check whether it received
an error for the latest read, so that we can ignore these interrupts
properly.
This is the only place I noticed where interrupts were handled
improperly.
AFAIK this can't happen in reality because we don't install signal
handlers, but it's good practice.