Skip to content

Commit

Permalink
apply cosmetic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ousret committed Mar 21, 2024
1 parent 8c3c77a commit 088fee7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
16 changes: 8 additions & 8 deletions httpie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ def metadata(self) -> str:
# metrics aren't guaranteed to be there. act with caution.
# see https://niquests.readthedocs.io/en/latest/user/advanced.html#event-hooks for more.
if hasattr(self._orig, "conn_info") and self._orig.conn_info:
if self._orig.conn_info.resolution_latency:
data[ELAPSED_DNS_RESOLUTION_LABEL] = str(round(self._orig.conn_info.resolution_latency.total_seconds(), 10)) + 's'
if self._orig.conn_info.established_latency:
data[ELAPSED_ESTABLISH_CONN] = str(round(self._orig.conn_info.established_latency.total_seconds(), 10)) + 's'
if self._orig.conn_info.tls_handshake_latency:
data[ELAPSED_TLS_HANDSHAKE] = str(round(self._orig.conn_info.tls_handshake_latency.total_seconds(), 10)) + 's'
if self._orig.conn_info.request_sent_latency:
data[ELAPSED_REQUEST_SEND] = str(round(self._orig.conn_info.request_sent_latency.total_seconds(), 10)) + 's'
if self._orig.conn_info.resolution_latency is not None:
data[ELAPSED_DNS_RESOLUTION_LABEL] = f"{round(self._orig.conn_info.resolution_latency.total_seconds(), 10):9f}s"
if self._orig.conn_info.established_latency is not None:
data[ELAPSED_ESTABLISH_CONN] = f"{round(self._orig.conn_info.established_latency.total_seconds(), 10):9f}s"
if self._orig.conn_info.tls_handshake_latency is not None:
data[ELAPSED_TLS_HANDSHAKE] = f"{round(self._orig.conn_info.tls_handshake_latency.total_seconds(), 10):9f}s"
if self._orig.conn_info.request_sent_latency is not None:
data[ELAPSED_REQUEST_SEND] = f"{round(self._orig.conn_info.request_sent_latency.total_seconds(), 10):9f}s"

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

Expand Down
4 changes: 2 additions & 2 deletions httpie/output/lexers/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SimplifiedHTTPLexer(pygments.lexer.RegexLexer):
tokens = {
'root': [
# Request-Line
(r'([A-Z]+)( +)([^ ]+)( +)(HTTP)(/)(\d+\.\d+)',
(r'([A-Z]+)( +)([^ ]+)( +)(HTTP)(/)((\d+\.\d+)|(\d+))',
pygments.lexer.bygroups(
request_method,
pygments.token.Text,
Expand All @@ -77,7 +77,7 @@ class SimplifiedHTTPLexer(pygments.lexer.RegexLexer):
pygments.token.Number
)),
# Response Status-Line
(r'(HTTP)(/)(\d+\.\d+)( +)(.+)',
(r'(HTTP)(/)((\d+\.\d+)|(\d+))( +)(.+)',
pygments.lexer.bygroups(
pygments.token.Keyword.Reserved, # 'HTTP'
pygments.token.Operator, # '/'
Expand Down
1 change: 1 addition & 0 deletions httpie/output/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __iter__(self) -> Iterable[bytes]:
yield b'\n\n'

yield self.get_metadata()
yield b'\n'


class RawStream(BaseStream):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def test_meta_extended_tls(remote_httpbin_secure):
assert 'Issuer' in r
assert 'Revocation status' in r

# If this fail, you missed an extraneous RC after the metadata render.
assert str(r).endswith("\n")


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

0 comments on commit 088fee7

Please sign in to comment.