Skip to content

Commit 4c246e4

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

Some content is hidden

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

42 files changed

+408
-246
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 }}

docs/README.md

+58-19
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,24 +1592,38 @@ $ 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+
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+
16021609
Elapsed time: 1.099171542s
16031610
```
16041611
16051612
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:
16061613
16071614
```bash
1608-
$ http --print=hm pie.dev/get
1615+
$ https --print=hm pie.dev/get
16091616
```
16101617
16111618
```http
1612-
HTTP/1.1 200 OK
1619+
Connected to: 2a06:98c1:3120::2 port 443
1620+
Connection secured using: TLSv1.3 with AES-256-GCM-SHA384
1621+
Server certificate: commonName="pie.dev"; DNS="*.pie.dev"; DNS="pie.dev"
1622+
Certificate validity: "Nov 11 01:14:24 2023 UTC" to "Feb 09 01:14:23 2024 UTC"
1623+
Issuer: countryName="US"; organizationName="Let's Encrypt"; commonName="E1"
1624+
Revocation status: Good
1625+
1626+
HTTP/2 200 OK
16131627
Content-Type: application/json
16141628
16151629
Elapsed time: 0.077538375s
@@ -1626,19 +1640,19 @@ If you [use `--style` with one of the Pie themes](#colors-and-formatting), you
16261640
`--verbose` can often be useful for debugging the request and generating documentation examples:
16271641
16281642
```bash
1629-
$ http --verbose PUT pie.dev/put hello=world
1630-
PUT /put HTTP/1.1
1643+
$ https --verbose PUT pie.dev/put hello=world
1644+
PUT /put HTTP/2
16311645
Accept: application/json, */*;q=0.5
16321646
Accept-Encoding: gzip, deflate
16331647
Content-Type: application/json
16341648
Host: pie.dev
1635-
User-Agent: HTTPie/0.2.7dev
1649+
User-Agent: HTTPie/4.0.0
16361650
16371651
{
16381652
"hello": "world"
16391653
}
16401654
1641-
HTTP/1.1 200 OK
1655+
HTTP/2 200 OK
16421656
Connection: keep-alive
16431657
Content-Length: 477
16441658
Content-Type: application/json
@@ -1652,10 +1666,10 @@ Server: gunicorn/0.13.4
16521666
16531667
#### Extra verbose output
16541668
1655-
If you run HTTPie with `-vv` or `--verbose --verbose`, then it would also display the [response metadata](#response-meta).
1669+
If you run HTTPie with `-vv` or `--verbose --verbose`, then it would also display the [response and request metadata](#response-meta).
16561670
16571671
```bash
1658-
# Just like the above, but with additional columns like the total elapsed time
1672+
# Just like the above, but with additional columns like the total elapsed time, remote peer connection informations
16591673
$ http -vv pie.dev/get
16601674
```
16611675
@@ -1833,6 +1847,31 @@ $ http --chunked pie.dev/post @files/data.xml
18331847
$ cat files/data.xml | http --chunked pie.dev/post
18341848
```
18351849
1850+
## Disable HTTP/2, or HTTP/3
1851+
1852+
You can at your own discretion toggle on and off HTTP/2, or/and HTTP/3.
1853+
1854+
```bash
1855+
$ https --disable-http2 PUT pie.dev/put hello=world
1856+
```
1857+
1858+
```bash
1859+
$ https --disable-http3 PUT pie.dev/put hello=world
1860+
```
1861+
1862+
## Force HTTP/3
1863+
1864+
By opposition to the previous section, you can force the HTTP/3 negotiation.
1865+
1866+
```bash
1867+
$ https --http3 pie.dev/get
1868+
```
1869+
1870+
By default, HTTPie cannot negotiate HTTP/3 without a first HTTP/1.1, or HTTP/2 successful response.
1871+
The remote server yield its support for HTTP/3 in the Alt-Svc header, if present HTTPie will issue
1872+
the successive requests via HTTP/3. You may use that argument in case the remote peer does not support
1873+
either HTTP/1.1 or HTTP/2.
1874+
18361875
## Compressed request body
18371876
18381877
You can use the `--compress, -x` flag to instruct HTTPie to use `Content-Encoding: deflate` and compress the request data:
@@ -2556,7 +2595,7 @@ HTTPie has the following community channels:
25562595
25572596
Under the hood, HTTPie uses these two amazing libraries:
25582597
2559-
- [Requests](https://requests.readthedocs.io/en/latest/) — Python HTTP library for humans
2598+
- [Niquests](https://niquests.readthedocs.io/en/latest/) — Python HTTP library for humans
25602599
- [Pygments](https://pygments.org/) — Python syntax highlighter
25612600
25622601
#### 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'
7+
__date__ = '2023-10-11'
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

+26
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,32 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False):
802802
'The Transfer-Encoding header is set to chunked.'
803803
)
804804
)
805+
network.add_argument(
806+
"--disable-http2",
807+
default=False,
808+
action="store_true",
809+
short_help="Disable the HTTP/2 protocol."
810+
)
811+
network.add_argument(
812+
"--disable-http3",
813+
default=False,
814+
action="store_true",
815+
short_help="Disable the HTTP/3 over QUIC protocol."
816+
)
817+
network.add_argument(
818+
"--http3",
819+
default=False,
820+
dest="force_http3",
821+
action="store_true",
822+
short_help="Use the HTTP/3 protocol for the request.",
823+
help="""
824+
By default, HTTPie cannot negotiate HTTP/3 without a first HTTP/1.1, or HTTP/2 successful response.
825+
The remote server yield its support for HTTP/3 in the Alt-Svc header, if present HTTPie will issue
826+
the successive requests via HTTP/3. You may use that argument in case the remote peer does not support
827+
either HTTP/1.1 or HTTP/2.
828+
829+
"""
830+
)
805831

806832
#######################################################################
807833
# SSL

0 commit comments

Comments
 (0)