Skip to content

Commit 7eb10b5

Browse files
author
Ahmed TAHRI
committed
add comments to guide future developers
1 parent 8037485 commit 7eb10b5

File tree

8 files changed

+36
-7
lines changed

8 files changed

+36
-7
lines changed

docs/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1530,13 +1530,13 @@ $ http --cert=client.pem --cert-key=client.key --cert-key-pass=my_password https
15301530
### SSL version
15311531
15321532
Use the `--ssl=<PROTOCOL>` option to specify the desired protocol version to use.
1533-
This will default to SSL v2.3 which will negotiate the highest protocol that both the server and your installation of OpenSSL support.
1534-
The available protocols are `ssl2.3`, `ssl3`, `tls1`, `tls1.1`, `tls1.2`, `tls1.3`.
1533+
This will default to TLS v1.0 which will negotiate the highest protocol that both the server and your installation of OpenSSL support.
1534+
The available protocols are `tls1`, `tls1.1`, `tls1.2`, `tls1.3`.
15351535
(The actually available set of protocols may vary depending on your OpenSSL installation.)
15361536
15371537
```bash
1538-
# Specify the vulnerable SSL v3 protocol to talk to an outdated server:
1539-
$ http --ssl=ssl3 https://vulnerable.example.org
1538+
# Specify the vulnerable TLS 1 protocol to talk to an outdated server:
1539+
$ http --ssl=tls1 https://vulnerable.example.org
15401540
```
15411541
15421542
### SSL ciphers

httpie/cli/argparser.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ def parse_args(
175175
self._process_pretty_options()
176176
self._process_format_options()
177177

178-
# bellow is a fix for detecting "false-or empty" stdin
178+
# bellow is a fix for detecting "false-or empty" stdin.
179+
# see https://github.com/httpie/cli/issues/1551 for more information.
179180
if self.has_stdin_data:
180181
read_event = threading.Event()
181182
observe_stdin_for_data_thread(env, self.env.stdin, read_event)

httpie/client.py

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from urllib.parse import urlparse, urlunparse
99

1010
import niquests
11+
# to understand why this is required
12+
# see https://niquests.readthedocs.io/en/latest/community/faq.html#what-is-urllib3-future
1113
from niquests._compat import HAS_LEGACY_URLLIB3
1214

1315
if not HAS_LEGACY_URLLIB3:
@@ -120,6 +122,10 @@ def collect_messages(
120122

121123
hooks = None
122124

125+
# The hook set up bellow is crucial for HTTPie.
126+
# It will help us yield the request before it is
127+
# actually sent. This will permit us to know about
128+
# the connection information for example.
123129
if prepared_request_readiness:
124130
hooks = {"pre_send": [prepared_request_readiness]}
125131

httpie/core.py

+6
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ def request_body_read_callback(chunk: bytes):
206206
downloader.pre_request(args.headers)
207207

208208
def prepared_request_readiness(pr):
209+
"""This callback is meant to output the request part. It is triggered by
210+
the underlying Niquests library just after establishing the connection."""
209211

210212
oo = OutputOptions.from_message(
211213
pr,
@@ -252,7 +254,11 @@ def prepared_request_readiness(pr):
252254
is_streamed_upload = not isinstance(message.body, (str, bytes))
253255
do_write_body = not is_streamed_upload
254256
force_separator = is_streamed_upload and env.stdout_isatty
257+
# We're in a REQUEST message, we rather output the message
258+
# in prepared_request_readiness because we want "message.conn_info"
259+
# to be set appropriately. (e.g. know about HTTP protocol version, etc...)
255260
if message.conn_info is None and not args.offline:
261+
# bellow variable will be accessed by prepared_request_readiness just after.
256262
prev_with_body = output_options.body
257263
continue
258264
else:

httpie/internal/encoder.py

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import os
2222
from uuid import uuid4
2323

24+
# to understand why this is required
25+
# see https://niquests.readthedocs.io/en/latest/community/faq.html#what-is-urllib3-future
2426
from niquests._compat import HAS_LEGACY_URLLIB3
2527

2628
if HAS_LEGACY_URLLIB3:

httpie/models.py

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import niquests
44

5+
# to understand why this is required
6+
# see https://niquests.readthedocs.io/en/latest/community/faq.html#what-is-urllib3-future
57
from niquests._compat import HAS_LEGACY_URLLIB3
68

79
if not HAS_LEGACY_URLLIB3:
@@ -109,6 +111,8 @@ def metadata(self) -> str:
109111
time_since_headers_parsed = monotonic() - self._orig._httpie_headers_parsed_at
110112
time_elapsed = time_to_parse_headers + time_since_headers_parsed
111113

114+
# metrics aren't guaranteed to be there. act with caution.
115+
# see https://niquests.readthedocs.io/en/latest/user/advanced.html#event-hooks for more.
112116
if hasattr(self._orig, "conn_info") and self._orig.conn_info:
113117
if self._orig.conn_info.resolution_latency:
114118
data[ELAPSED_DNS_RESOLUTION_LABEL] = str(round(self._orig.conn_info.resolution_latency.total_seconds(), 10)) + 's'

httpie/output/streams.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __iter__(self) -> Iterable[bytes]:
9191
class RawStream(BaseStream):
9292
"""The message is streamed in chunks with no processing."""
9393

94-
CHUNK_SIZE = -1
94+
CHUNK_SIZE = -1 # '-1' means that we want to receive chunks exactly as they arrive.
9595
CHUNK_SIZE_BY_LINE = 1
9696

9797
def __init__(self, chunk_size=CHUNK_SIZE, **kwargs):

httpie/ssl_.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
resolve_ssl_version,
1313
)
1414

15-
15+
# the minimum one may hope to negotiate with Python 3.7+ is tls1+
16+
# anything else would be unsupported.
1617
SSL_VERSION_ARG_MAPPING = {
18+
'tls1': 'PROTOCOL_TLSv1',
19+
'tls1.1': 'PROTOCOL_TLSv1_1',
1720
'tls1.2': 'PROTOCOL_TLSv1_2',
1821
'tls1.3': 'PROTOCOL_TLSv1_3',
1922
}
23+
# todo: we'll need to update this in preparation for Python 3.13+
24+
# could be a removal (after a long deprecation about constants
25+
# PROTOCOL_TLSv1, PROTOCOL_TLSv1_1, ...).
2026
AVAILABLE_SSL_VERSION_ARG_MAPPING = {
2127
arg: getattr(ssl, constant_name)
2228
for arg, constant_name in SSL_VERSION_ARG_MAPPING.items()
@@ -27,6 +33,9 @@
2733
class QuicCapabilityCache(
2834
MutableMapping[Tuple[str, int], Optional[Tuple[str, int]]]
2935
):
36+
"""This class will help us keep (persistent across runs) what hosts are QUIC capable.
37+
See https://urllib3future.readthedocs.io/en/latest/advanced-usage.html#remembering-http-3-over-quic-support for
38+
the implementation guide."""
3039

3140
def __init__(self):
3241
self._cache = {}
@@ -77,6 +86,7 @@ def to_raw_cert(self):
7786
"""Synthesize a requests-compatible (2-item tuple of cert and key file)
7887
object from HTTPie's internal representation of a certificate."""
7988
if self.key_password:
89+
# Niquests support 3-tuple repr in addition to the 2-tuple repr
8090
return self.cert_file, self.key_file, self.key_password
8191
return self.cert_file, self.key_file
8292

0 commit comments

Comments
 (0)