Skip to content

Commit c201f05

Browse files
author
Ahmed TAHRI
committed
apply cosmetic fixes
1 parent 8c3c77a commit c201f05

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

httpie/models.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ def metadata(self) -> str:
103103
# metrics aren't guaranteed to be there. act with caution.
104104
# see https://niquests.readthedocs.io/en/latest/user/advanced.html#event-hooks for more.
105105
if hasattr(self._orig, "conn_info") and self._orig.conn_info:
106-
if self._orig.conn_info.resolution_latency:
107-
data[ELAPSED_DNS_RESOLUTION_LABEL] = str(round(self._orig.conn_info.resolution_latency.total_seconds(), 10)) + 's'
108-
if self._orig.conn_info.established_latency:
109-
data[ELAPSED_ESTABLISH_CONN] = str(round(self._orig.conn_info.established_latency.total_seconds(), 10)) + 's'
110-
if self._orig.conn_info.tls_handshake_latency:
111-
data[ELAPSED_TLS_HANDSHAKE] = str(round(self._orig.conn_info.tls_handshake_latency.total_seconds(), 10)) + 's'
112-
if self._orig.conn_info.request_sent_latency:
113-
data[ELAPSED_REQUEST_SEND] = str(round(self._orig.conn_info.request_sent_latency.total_seconds(), 10)) + 's'
106+
if self._orig.conn_info.resolution_latency is not None:
107+
data[ELAPSED_DNS_RESOLUTION_LABEL] = f"{round(self._orig.conn_info.resolution_latency.total_seconds(), 10):9f}s"
108+
if self._orig.conn_info.established_latency is not None:
109+
data[ELAPSED_ESTABLISH_CONN] = f"{round(self._orig.conn_info.established_latency.total_seconds(), 10):9f}s"
110+
if self._orig.conn_info.tls_handshake_latency is not None:
111+
data[ELAPSED_TLS_HANDSHAKE] = f"{round(self._orig.conn_info.tls_handshake_latency.total_seconds(), 10):9f}s"
112+
if self._orig.conn_info.request_sent_latency is not None:
113+
data[ELAPSED_REQUEST_SEND] = f"{round(self._orig.conn_info.request_sent_latency.total_seconds(), 10):9f}s"
114114

115115
data[ELAPSED_TIME_LABEL] = str(round(time_elapsed, 10)) + 's'
116116

httpie/output/lexers/http.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class SimplifiedHTTPLexer(pygments.lexer.RegexLexer):
6666
tokens = {
6767
'root': [
6868
# Request-Line
69-
(r'([A-Z]+)( +)([^ ]+)( +)(HTTP)(/)(\d+\.\d+)',
69+
(r'([A-Z]+)( +)([^ ]+)( +)(HTTP)(/)([0-9].?[0-9]?)',
7070
pygments.lexer.bygroups(
7171
request_method,
7272
pygments.token.Text,
@@ -77,7 +77,7 @@ class SimplifiedHTTPLexer(pygments.lexer.RegexLexer):
7777
pygments.token.Number
7878
)),
7979
# Response Status-Line
80-
(r'(HTTP)(/)(\d+\.\d+)( +)(.+)',
80+
(r'(HTTP)(/)([0-9].?[0-9]?)( +)(.+)',
8181
pygments.lexer.bygroups(
8282
pygments.token.Keyword.Reserved, # 'HTTP'
8383
pygments.token.Operator, # '/'

httpie/output/streams.py

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def __iter__(self) -> Iterable[bytes]:
8686
yield b'\n\n'
8787

8888
yield self.get_metadata()
89+
yield b'\n'
8990

9091

9192
class RawStream(BaseStream):

tests/test_meta.py

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def test_meta_extended_tls(remote_httpbin_secure):
1919
assert 'Issuer' in r
2020
assert 'Revocation status' in r
2121

22+
# If this fail, you missed an extraneous RC after the metadata render.
23+
# see output/streams.py L89
24+
assert str(r).endswith("\n")
25+
2226

2327
@pytest.mark.parametrize('style', ['auto', 'fruity', *PIE_STYLE_NAMES])
2428
def test_meta_elapsed_time_colors(httpbin, style):

0 commit comments

Comments
 (0)