Skip to content

Commit

Permalink
Fix displaying of status code without a status message.
Browse files Browse the repository at this point in the history
  • Loading branch information
isidentical committed Feb 23, 2022
1 parent 225dccb commit eab137d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## [3.0.3.dev0](https://github.com/httpie/httpie/compare/3.0.2...HEAD) (Unreleased)

- Fixed escaping of integer indexes with multiple backslashes in the nested JSON builder. ([#1285](https://github.com/httpie/httpie/issues/1285))
- Fixed displaying of status code without a status message on non-`auto` themes. ([#1300](https://github.com/httpie/httpie/issues/1300))

## [3.0.2](https://github.com/httpie/httpie/compare/3.0.1...3.0.2) (2022-01-24)

Expand Down
2 changes: 1 addition & 1 deletion httpie/output/lexers/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pygments
from httpie.output.lexers.common import precise

RE_STATUS_LINE = re.compile(r'(\d{3})( +)(.+)')
RE_STATUS_LINE = re.compile(r'(\d{3})( +)?(.+)?')

STATUS_TYPES = {
'1': pygments.token.Number.HTTP.INFO,
Expand Down
11 changes: 9 additions & 2 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
)
from httpie.cli.definition import parser
from httpie.encoding import UTF8
from httpie.output.formatters.colors import get_lexer, PIE_STYLE_NAMES
from httpie.output.formatters.colors import get_lexer, PIE_STYLE_NAMES, BUNDLED_STYLES
from httpie.status import ExitStatus
from .fixtures import XML_DATA_RAW, XML_DATA_FORMATTED
from .utils import COLOR, CRLF, HTTP_OK, MockEnvironment, http, DUMMY_URL
from .utils import COLOR, CRLF, HTTP_OK, MockEnvironment, http, DUMMY_URL, strip_colors


@pytest.mark.parametrize('stdout_isatty', [True, False])
Expand Down Expand Up @@ -234,6 +234,13 @@ def test_ensure_meta_is_colored(httpbin, style):
assert COLOR in r


@pytest.mark.parametrize('style', BUNDLED_STYLES)
def test_ensure_status_code_is_shown_on_all_themes(http_server, style):
env = MockEnvironment(colors=256)
r = http('--style', style, 'GET', http_server + '/status/no-msg', env=env)
assert 'HTTP/1.0 200' in strip_colors(r)


class TestPrettyOptions:
"""Test the --pretty handling."""

Expand Down
6 changes: 6 additions & 0 deletions tests/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
TESTS_ROOT = Path(__file__).parent.parent
CRLF = '\r\n'
COLOR = '\x1b['
COLOR_RE = re.compile(r'\x1b\[\d+(;\d+)*?m', re.MULTILINE)

HTTP_OK = '200 OK'
# noinspection GrazieInspection
HTTP_OK_COLOR = (
Expand All @@ -38,6 +40,10 @@
DUMMY_URL = 'http://this-should.never-resolve' # Note: URL never fetched


def strip_colors(colorized_msg: str) -> str:
return COLOR_RE.sub('', colorized_msg)


def mk_config_dir() -> Path:
dirname = tempfile.mkdtemp(prefix='httpie_config_')
return Path(dirname)
Expand Down
8 changes: 8 additions & 0 deletions tests/utils/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import pytest

STATUS_EMPTY_MSG = ''


class TestHandler(BaseHTTPRequestHandler):
handlers = defaultdict(dict)
Expand Down Expand Up @@ -73,6 +75,12 @@ def random_encoding(handler):
handler.wfile.write('0\r\n\r\n'.encode('utf-8'))


@TestHandler.handler('GET', '/status/no-msg')
def status_no_msg(handler):
handler.send_response(200, STATUS_EMPTY_MSG)
handler.end_headers()


@pytest.fixture(scope="function")
def http_server():
"""A custom HTTP server implementation for our tests, that is
Expand Down

0 comments on commit eab137d

Please sign in to comment.