Skip to content

Commit df42bba

Browse files
author
Ahmed TAHRI
committed
⚗️ Try compatible fork Niquests to supercharge HTTPie
1 parent e52a60e commit df42bba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+539
-259
lines changed

.github/workflows/tests.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ jobs:
2525
fail-fast: false
2626
matrix:
2727
os: [ubuntu-latest, macos-latest, windows-latest]
28-
python-version: [3.7, 3.8, 3.9, "3.10"]
29-
pyopenssl: [0, 1]
28+
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
3029
runs-on: ${{ matrix.os }}
3130
steps:
3231
- uses: actions/checkout@v3
@@ -39,12 +38,8 @@ jobs:
3938
python -m pip install --upgrade pip wheel
4039
python -m pip install --upgrade '.[dev]'
4140
python -m pytest --verbose ./httpie ./tests
42-
env:
43-
HTTPIE_TEST_WITH_PYOPENSSL: ${{ matrix.pyopenssl }}
4441
- name: Linux & Mac setup
4542
if: matrix.os != 'windows-latest'
4643
run: |
4744
make install
4845
make test
49-
env:
50-
HTTPIE_TEST_WITH_PYOPENSSL: ${{ matrix.pyopenssl }}

CHANGELOG.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
This document records all notable changes to [HTTPie](https://httpie.io).
44
This project adheres to [Semantic Versioning](https://semver.org/).
55

6-
## [3.3.0-dev](https://github.com/httpie/cli/compare/3.2.2...master) (unreleased)
7-
8-
- Make it possible to [unset](https://httpie.io/docs/cli/default-request-headers) the `User-Agent`, `Accept-Encoding`, and `Host` request headers. ([#1502](https://github.com/httpie/cli/issues/1502))
6+
## [4.0.0.b1](https://github.com/httpie/cli/compare/3.2.2...master) (unreleased)
7+
8+
- Make it possible to [unset](https://httpie.io/docs/cli/default-request-headers) the `User-Agent`, and `Accept-Encoding` headers. ([#1502](https://github.com/httpie/cli/issues/1502))
9+
- Dependency on requests was changed in favor of compatible niquests. ([#1531](https://github.com/httpie/cli/pull/1531))
10+
- Added support for HTTP/2, and HTTP/3 protocols. ([#523](https://github.com/httpie/cli/issues/523)) ([#692](https://github.com/httpie/cli/issues/692)) ([#1531](https://github.com/httpie/cli/pull/1531))
11+
- Added request metadata for the TLS certificate, negotiated version with cipher, and his revocation status and the remote peer IP address. ([#1495](https://github.com/httpie/cli/issues/1495)) ([#1023](https://github.com/httpie/cli/issues/1023)) ([#826](https://github.com/httpie/cli/issues/826)) ([#1531](https://github.com/httpie/cli/pull/1531))
12+
- Added support to load the operating system trust store for the peer certificate validation. ([#480](https://github.com/httpie/cli/issues/480)) ([#1531](https://github.com/httpie/cli/pull/1531))
13+
- Added detailed timings in response metadata with DNS resolution, established, TLS handshake, and request sending delays. ([#1023](https://github.com/httpie/cli/issues/1023)) ([#1531](https://github.com/httpie/cli/pull/1531))
14+
- Added support for using alternative DNS resolver using `--resolver`. DNS over HTTPS, DNS over TLS, DNS over QUIC, and DNS over UDP are accepted. ([#99](https://github.com/httpie/cli/issues/99)) ([#1531](https://github.com/httpie/cli/pull/1531))
15+
- Added support for binding to a specific network adapter with `--interface`. ([#1422](https://github.com/httpie/cli/issues/1422)) ([#1531](https://github.com/httpie/cli/pull/1531))
16+
- Added support for forcing either IPv4 or IPv6 to reach the remote HTTP server with `-6` or `-4`. ([#94](https://github.com/httpie/cli/issues/94)) ([#1531](https://github.com/httpie/cli/pull/1531))
17+
- Removed support for pyopenssl. ([#1531](https://github.com/httpie/cli/pull/1531))
918

1019
## [3.2.2](https://github.com/httpie/cli/compare/3.2.1...3.2.2) (2022-05-19)
1120

docs/README.md

+97-21
Original file line numberDiff line numberDiff line change
@@ -1562,9 +1562,9 @@ be printed via several options:
15621562
|---------------------------:|----------------------------------------------------------------------------------------------------|
15631563
| `--headers, -h` | Only the response headers are printed |
15641564
| `--body, -b` | Only the response body is printed |
1565-
| `--meta, -m` | Only the [response metadata](#response-meta) is printed |
1565+
| `--meta, -m` | Only the [request, response metadata](#response-meta) are printed |
15661566
| `--verbose, -v` | Print the whole HTTP exchange (request and response). This option also enables `--all` (see below) |
1567-
| `--verbose --verbose, -vv` | Just like `-v`, but also include the response metadata. |
1567+
| `--verbose --verbose, -vv` | Just like `-v`, but also include the request, and response metadata. |
15681568
| `--print, -p` | Selects parts of the HTTP exchange |
15691569
| `--quiet, -q` | Don’t print anything to `stdout` and `stderr` |
15701570
@@ -1573,13 +1573,13 @@ be printed via several options:
15731573
All the other [output options](#output-options) are under the hood just shortcuts for the more powerful `--print, -p`.
15741574
It accepts a string of characters each of which represents a specific part of the HTTP exchange:
15751575
1576-
| Character | Stands for |
1577-
|----------:|---------------------------------|
1578-
| `H` | request headers |
1579-
| `B` | request body |
1580-
| `h` | response headers |
1581-
| `b` | response body |
1582-
| `m` | [response meta](#response-meta) |
1576+
| Character | Stands for |
1577+
|----------:|------------------------------------------|
1578+
| `H` | request headers |
1579+
| `B` | request body |
1580+
| `h` | response headers |
1581+
| `b` | response body |
1582+
| `m` | [request, response meta](#response-meta) |
15831583
15841584
Print request and response headers:
15851585
@@ -1592,27 +1592,49 @@ $ http --print=Hh PUT pie.dev/put hello=world
15921592
The response metadata section currently includes the total time elapsed. It’s the number of seconds between opening the network connection and downloading the last byte of response the body.
15931593
15941594
1595-
To _only_ show the response metadata, use `--meta, -m` (analogically to `--headers, -h` and `--body, -b`):
1595+
To _only_ show the request, and response metadata, use `--meta, -m` (analogically to `--headers, -h` and `--body, -b`):
15961596
15971597
```bash
15981598
$ http --meta pie.dev/delay/1
15991599
```
16001600
16011601
```console
1602-
Elapsed time: 1.099171542s
1602+
Connected to: 2a06:98c1:3120::2 port 443
1603+
Connection secured using: TLSv1.3 with AES-256-GCM-SHA384
1604+
Server certificate: commonName="pie.dev"; DNS="*.pie.dev"; DNS="pie.dev"
1605+
Certificate validity: "Nov 11 01:14:24 2023 UTC" to "Feb 09 01:14:23 2024 UTC"
1606+
Issuer: countryName="US"; organizationName="Let's Encrypt"; commonName="E1"
1607+
Revocation status: Good
1608+
1609+
Elapsed DNS: 0.11338s
1610+
Elapsed established connection: 3.8e-05s
1611+
Elapsed TLS handshake: 0.057503s
1612+
Elapsed emitting request: 0.000275s
1613+
Elapsed time: 0.292854214s
16031614
```
16041615
16051616
The [extra verbose `-vv` output](#extra-verbose-output) includes the meta section by default. You can also show it in combination with other parts of the exchange via [`--print=m`](#what-parts-of-the-http-exchange-should-be-printed). For example, here we print it together with the response headers:
16061617
16071618
```bash
1608-
$ http --print=hm pie.dev/get
1619+
$ https --print=hm pie.dev/get
16091620
```
16101621
16111622
```http
1612-
HTTP/1.1 200 OK
1623+
Connected to: 2a06:98c1:3120::2 port 443
1624+
Connection secured using: TLSv1.3 with AES-256-GCM-SHA384
1625+
Server certificate: commonName="pie.dev"; DNS="*.pie.dev"; DNS="pie.dev"
1626+
Certificate validity: "Nov 11 01:14:24 2023 UTC" to "Feb 09 01:14:23 2024 UTC"
1627+
Issuer: countryName="US"; organizationName="Let's Encrypt"; commonName="E1"
1628+
Revocation status: Good
1629+
1630+
HTTP/2 200 OK
16131631
Content-Type: application/json
16141632
1615-
Elapsed time: 0.077538375s
1633+
Elapsed DNS: 0.11338s
1634+
Elapsed established connection: 3.8e-05s
1635+
Elapsed TLS handshake: 0.057503s
1636+
Elapsed emitting request: 0.000275s
1637+
Elapsed time: 0.292854214s
16161638
```
16171639
16181640
@@ -1626,19 +1648,19 @@ If you [use `--style` with one of the Pie themes](#colors-and-formatting), you
16261648
`--verbose` can often be useful for debugging the request and generating documentation examples:
16271649
16281650
```bash
1629-
$ http --verbose PUT pie.dev/put hello=world
1630-
PUT /put HTTP/1.1
1651+
$ https --verbose PUT pie.dev/put hello=world
1652+
PUT /put HTTP/2
16311653
Accept: application/json, */*;q=0.5
16321654
Accept-Encoding: gzip, deflate
16331655
Content-Type: application/json
16341656
Host: pie.dev
1635-
User-Agent: HTTPie/0.2.7dev
1657+
User-Agent: HTTPie/4.0.0
16361658
16371659
{
16381660
"hello": "world"
16391661
}
16401662
1641-
HTTP/1.1 200 OK
1663+
HTTP/2 200 OK
16421664
Connection: keep-alive
16431665
Content-Length: 477
16441666
Content-Type: application/json
@@ -1652,10 +1674,10 @@ Server: gunicorn/0.13.4
16521674
16531675
#### Extra verbose output
16541676
1655-
If you run HTTPie with `-vv` or `--verbose --verbose`, then it would also display the [response metadata](#response-meta).
1677+
If you run HTTPie with `-vv` or `--verbose --verbose`, then it would also display the [response and request metadata](#response-meta).
16561678
16571679
```bash
1658-
# Just like the above, but with additional columns like the total elapsed time
1680+
# Just like the above, but with additional columns like the total elapsed time, remote peer connection informations
16591681
$ http -vv pie.dev/get
16601682
```
16611683
@@ -1833,6 +1855,60 @@ $ http --chunked pie.dev/post @files/data.xml
18331855
$ cat files/data.xml | http --chunked pie.dev/post
18341856
```
18351857
1858+
## Disable HTTP/2, or HTTP/3
1859+
1860+
You can at your own discretion toggle on and off HTTP/2, or/and HTTP/3.
1861+
1862+
```bash
1863+
$ https --disable-http2 PUT pie.dev/put hello=world
1864+
```
1865+
1866+
```bash
1867+
$ https --disable-http3 PUT pie.dev/put hello=world
1868+
```
1869+
1870+
## Force HTTP/3
1871+
1872+
By opposition to the previous section, you can force the HTTP/3 negotiation.
1873+
1874+
```bash
1875+
$ https --http3 pie.dev/get
1876+
```
1877+
1878+
By default, HTTPie cannot negotiate HTTP/3 without a first HTTP/1.1, or HTTP/2 successful response unless the
1879+
remote host specified a DNS HTTPS record that indicate its support.
1880+
1881+
The remote server yield its support for HTTP/3 in the Alt-Svc header, if present HTTPie will issue
1882+
the successive requests via HTTP/3. You may use that argument in case the remote peer does not support
1883+
either HTTP/1.1 or HTTP/2.
1884+
1885+
## Custom DNS resolver
1886+
1887+
You can specify one or many custom DNS resolvers using the `--resolver` flag. They will be tested in
1888+
presented order to resolver given hostname.
1889+
1890+
```bash
1891+
$ https --resolver "doh+cloudflare://" pie.dev/get
1892+
```
1893+
1894+
To know more about DNS url and supported protocols, visit [Niquests documentation](https://niquests.readthedocs.io/en/stable/user/quickstart.html#dns-resolution).
1895+
1896+
## Attach to a specific network adapter
1897+
1898+
In order to bind emitted request from a specific network adapter you can use the `--interface` flag.
1899+
1900+
```bash
1901+
$ https --interface 172.17.0.1 pie.dev/get
1902+
```
1903+
1904+
## Enforcing IPv4 or IPv6
1905+
1906+
Since HTTPie 4, you may pass the flags `--ipv4, -4` or `--ipv6, -6` to enforce connecting to an IPv4 or IPv6 address.
1907+
1908+
```bash
1909+
$ https -4 pie.dev/get
1910+
```
1911+
18361912
## Compressed request body
18371913
18381914
You can use the `--compress, -x` flag to instruct HTTPie to use `Content-Encoding: deflate` and compress the request data:
@@ -2556,7 +2632,7 @@ HTTPie has the following community channels:
25562632
25572633
Under the hood, HTTPie uses these two amazing libraries:
25582634
2559-
- [Requests](https://requests.readthedocs.io/en/latest/) — Python HTTP library for humans
2635+
- [Niquests](https://niquests.readthedocs.io/en/latest/) — Python HTTP library for humans
25602636
- [Pygments](https://pygments.org/) — Python syntax highlighter
25612637
25622638
#### HTTPie friends

docs/contributors/fetch.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Generate the contributors database.
33
4-
FIXME: replace `requests` calls with the HTTPie API, when available.
4+
FIXME: replace `niquests` calls with the HTTPie API, when available.
55
"""
66
import json
77
import os
@@ -14,7 +14,7 @@
1414
from time import sleep
1515
from typing import Any, Dict, Optional, Set
1616

17-
import requests
17+
import niquests
1818

1919
FullNames = Set[str]
2020
GitHubLogins = Set[str]
@@ -197,10 +197,10 @@ def fetch(url: str, params: Optional[Dict[str, str]] = None) -> UserInfo:
197197
}
198198
for retry in range(1, 6):
199199
debug(f'[{retry}/5]', f'{url = }', f'{params = }')
200-
with requests.get(url, params=params, headers=headers) as req:
200+
with niquests.get(url, params=params, headers=headers) as req:
201201
try:
202202
req.raise_for_status()
203-
except requests.exceptions.HTTPError as exc:
203+
except niquests.exceptions.HTTPError as exc:
204204
if exc.response.status_code == 403:
205205
# 403 Client Error: rate limit exceeded for url: ...
206206
now = int(datetime.utcnow().timestamp())

httpie/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
"""
55

6-
__version__ = '3.2.2'
7-
__date__ = '2022-05-06'
6+
__version__ = '4.0.0.b1'
7+
__date__ = '2024-01-01'
88
__author__ = 'Jakub Roztocil'
99
__licence__ = 'BSD'

httpie/adapters.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from httpie.cli.dicts import HTTPHeadersDict
2-
from requests.adapters import HTTPAdapter
2+
from niquests.adapters import HTTPAdapter
33

44

55
class HTTPieHTTPAdapter(HTTPAdapter):

httpie/cli/argparser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from textwrap import dedent
88
from urllib.parse import urlsplit
99

10-
from requests.utils import get_netrc_auth
10+
from niquests.utils import get_netrc_auth
1111

1212
from .argtypes import (
1313
AuthCredentials, SSLCredentials, KeyValueArgType,

httpie/cli/definition.py

+60
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,20 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False):
726726
727727
""",
728728
)
729+
network.add_argument(
730+
'--ipv6',
731+
'-6',
732+
default=False,
733+
action='store_true',
734+
short_help='Force using a IPv6 address to reach the remote peer.'
735+
)
736+
network.add_argument(
737+
'--ipv4',
738+
'-4',
739+
default=False,
740+
action='store_true',
741+
short_help='Force using a IPv4 address to reach the remote peer.'
742+
)
729743
network.add_argument(
730744
'--follow',
731745
'-F',
@@ -802,6 +816,52 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False):
802816
'The Transfer-Encoding header is set to chunked.'
803817
)
804818
)
819+
network.add_argument(
820+
"--disable-http2",
821+
default=False,
822+
action="store_true",
823+
short_help="Disable the HTTP/2 protocol."
824+
)
825+
network.add_argument(
826+
"--disable-http3",
827+
default=False,
828+
action="store_true",
829+
short_help="Disable the HTTP/3 over QUIC protocol."
830+
)
831+
network.add_argument(
832+
"--http3",
833+
default=False,
834+
dest="force_http3",
835+
action="store_true",
836+
short_help="Use the HTTP/3 protocol for the request.",
837+
help="""
838+
By default, HTTPie cannot negotiate HTTP/3 without a first HTTP/1.1, or HTTP/2 successful response unless the
839+
remote host specified a DNS HTTPS record that indicate its support.
840+
841+
The remote server yield its support for HTTP/3 in the Alt-Svc header, if present HTTPie will issue
842+
the successive requests via HTTP/3. You may use that argument in case the remote peer does not support
843+
either HTTP/1.1 or HTTP/2.
844+
845+
"""
846+
)
847+
network.add_argument(
848+
"--resolver",
849+
default=[],
850+
action='append',
851+
short_help="Specify a DNS resolver url to resolve hostname.",
852+
help="""
853+
By default, HTTPie use the system DNS through Python standard library.
854+
You can specify an alternative DNS server to be used. (e.g. doh://cloudflare-dns.com or doh://google.dns).
855+
You can specify multiple resolvers with different protocols. The environment
856+
variable $NIQUESTS_DNS_URL is supported as well.
857+
858+
"""
859+
)
860+
network.add_argument(
861+
"--interface",
862+
default=None,
863+
short_help="Bind to a specific network interface.",
864+
)
805865

806866
#######################################################################
807867
# SSL

0 commit comments

Comments
 (0)