code cleanup

This commit is contained in:
Ahmed TAHRI
2024-03-20 06:45:56 +01:00
parent 7be49cfa34
commit 4f3b468970
8 changed files with 42 additions and 43 deletions

View File

@@ -1599,18 +1599,12 @@ $ http --meta pie.dev/delay/1
Revocation status: Good
HTTP/3 200 OK
Server certificate: commonName="pie.dev"; DNS="*.pie.dev"; DNS="pie.dev"
Certificate validity: "Nov 11 01:14:24 2023 UTC" to "Feb 09 01:14:23 2024 UTC"
Issuer: countryName="US"; organizationName="Let's Encrypt"; commonName="E1"
Revocation status: Good
HTTP/2 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
```
Please note that it also includes time spent on formatting the output, which adds a small penalty. Also, if the body is not part of the output, [we dont spend time downloading it](#conditional-body-download).
Alt-Svc: h3=":443"; ma=86400
Cf-Cache-Status: DYNAMIC
Cf-Ray: 867351f9cf37d4fe-CDG
Content-Encoding: br
Content-Type: application/json
Date: Wed, 20 Mar 2024 05:32:11 GMT
Server: cloudflare
@@ -1623,18 +1617,26 @@ $ https --print=hm pie.dev/get
If you [use `--style` with one of the Pie themes](#colors-and-formatting), youll see the time information color-coded (green/yellow/orange/red) based on how long the exchange took.
Accept-Encoding: gzip, deflate
### Verbose output
`--verbose` can often be useful for debugging the request and generating documentation examples:
```bash
$ https --verbose PUT pie.dev/put hello=world
PUT /put HTTP/2
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json
Host: pie.dev
User-Agent: HTTPie/4.0.0
{
"hello": "world"
}
HTTP/2 200 OK
Connection: keep-alive
Content-Length: 477
}
HTTP/2 200 OK
Connection: keep-alive
Content-Length: 477
Content-Type: application/json
Date: Sun, 05 Aug 2012 00:25:23 GMT
Server: gunicorn/0.13.4
@@ -1876,7 +1878,7 @@ $ https --http3 pie.dev/get
$ https --resolver "in-memory://default/?hosts=pie.dev:10.10.4.1" pie.dev/get
```
In that example, `pie.dev` will resolve to `10.10.4.1`. The TLS HELLO / SNI will be set with host = `pie.dev`.
In that example, `pie.dev` will resolve to `10.10.4.1`. The TLS HELLO / SNI will be set with host = `pie.dev`.
HTTPie allows to pass directly the hostname and associated IPs directly as a shortcut to previous the example like so:
@@ -1893,7 +1895,7 @@ presented order to resolver given hostname.
## Attach to a specific network adapter
In order to bind emitted request from a specific network adapter you can use the `--interface` flag.
```bash
$ https --interface 172.17.0.1 pie.dev/get
```
@@ -1928,13 +1930,13 @@ $ https --interface 172.17.0.1 pie.dev/get
```bash
$ http --compress pie.dev/post @files/data.xml
```
```
```bash
$ cat files/data.xml | http --compress pie.dev/post
```
If compressing the data does not save size, HTTPie sends it untouched. To always compress the data, specify `--compress, -x` twice:
If compressing the data does not save size, HTTPie sends it untouched. To always compress the data, specify `--compress, -x` twice:
```bash
$ http -xx PUT pie.dev/put hello=world
@@ -2123,13 +2125,23 @@ $ http --download https://github.com/httpie/cli/archive/master.tar.gz
To prevent data loss by overwriting, HTTPie adds a unique numerical suffix to the filename when necessary (unless specified with `--output, -o`).
### Piping while downloading
This only works with servers that support `Range` requests and `206 Partial Content` responses.
If the server doesnt support that, the whole file will simply be downloaded:
You can also redirect the response body to another program while the response headers and progress are still shown in the terminal:
```bash
$ http -d https://github.com/httpie/cli/archive/master.tar.gz | tar zxf -
```
### Resuming downloads
If `--output, -o` is specified, you can resume a partial download using the `--continue, -c` option.
This only works with servers that support `Range` requests and `206 Partial Content` responses.
If the server doesnt support that, the whole file will simply be downloaded:
```bash
$ http -dco file.zip example.org/file
```
```
`-dco` is shorthand for `--download` `--continue` `--output`.
### Other notes

View File

@@ -41,8 +41,6 @@ def _fetch_updates(env: Environment) -> str:
file = env.config.version_info_file
data = _read_data_error_free(file)
print("fetch update...?")
response = niquests.get(PACKAGE_INDEX_LINK, verify=False)
response.raise_for_status()

View File

@@ -4,8 +4,6 @@ import json
import os.path
from os import makedirs
from niquests import Response
from httpie.config import DEFAULT_CONFIG_DIR
from httpie.adapters import HTTPAdapter
# noinspection PyPackageRequirements
@@ -146,13 +144,6 @@ class HTTPieHTTPSAdapter(HTTPAdapter):
def get_default_ciphers_names(cls):
return [cipher['name'] for cipher in cls._create_ssl_context(verify=False).get_ciphers()]
def send(
self,
*args,
**kwargs
) -> Response:
return super().send(*args, **kwargs)
def _is_key_file_encrypted(key_file):
"""Detects if a key file is encrypted or not.

View File

@@ -92,7 +92,7 @@ def test_missing_auth(httpbin):
def test_netrc(httpbin_both):
# This one gets handled by requests (no --auth, --auth-type present),
# This one gets handled by niquests (no --auth, --auth-type present),
# thats why we patch inside `niquests.sessions`.
with mock.patch('niquests.sessions.get_netrc_auth') as get_netrc_auth:
get_netrc_auth.return_value = ('httpie', 'password')

View File

@@ -38,7 +38,7 @@ class TestIntegration:
""""HTTP request handler."""
def do_GET(self):
"""Handle GET niquests."""
"""Handle GET requests."""
# Craft multiple cookies
cookie = SimpleCookie()
cookie['hello'] = 'world'

View File

@@ -168,7 +168,6 @@ def test_terminal_output_response_content_type_charset_with_stream(charset, text
method=responses.GET,
url=DUMMY_URL,
body=f'<?xml version="1.0"?>\n<c>{text}</c>'.encode(charset),
# stream=True,
content_type=f'text/xml; charset={charset.upper()}',
)
r = http('--pretty', pretty, '--stream', DUMMY_URL)

View File

@@ -285,7 +285,7 @@ class TestMultipartFormDataFileUpload:
assert r.count(boundary) == 4
def test_multipart_custom_content_type_boundary_preserved(self, httpbin):
# Allow explicit nonsense niquests.
# Allow explicit nonsense requests.
boundary_in_header = 'HEADER_BOUNDARY'
boundary_in_body = 'BODY_BOUNDARY'
r = http(

View File

@@ -58,7 +58,6 @@ class OutputMatchingError(ValueError):
def expect_tokens(tokens: Iterable[Expect], s: str):
for token in tokens:
s = expect_token(token, s)
# print(token, "OK")
if s:
raise OutputMatchingError(f'Unmatched remaining output for {tokens} in {s!r}')