You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2026-04-24 19:53:55 +02:00
Fix displaying of status code without a status message. (#1301)
Co-authored-by: Jakub Roztocil <jakub@roztocil.co>
This commit is contained in:
@@ -27,6 +27,8 @@ HTTPBIN_WITH_CHUNKED_SUPPORT = 'http://' + HTTPBIN_WITH_CHUNKED_SUPPORT_DOMAIN
|
||||
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 = (
|
||||
@@ -38,6 +40,10 @@ HTTP_OK_COLOR = (
|
||||
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)
|
||||
|
||||
@@ -18,14 +18,17 @@ class TestHandler(BaseHTTPRequestHandler):
|
||||
return func
|
||||
return inner
|
||||
|
||||
def do_GET(self):
|
||||
def do_generic(self):
|
||||
parse_result = urlparse(self.path)
|
||||
func = self.handlers['GET'].get(parse_result.path)
|
||||
func = self.handlers[self.command].get(parse_result.path)
|
||||
if func is None:
|
||||
return self.send_error(HTTPStatus.NOT_FOUND)
|
||||
|
||||
return func(self)
|
||||
|
||||
do_GET = do_generic
|
||||
do_POST = do_generic
|
||||
|
||||
|
||||
@TestHandler.handler('GET', '/headers')
|
||||
def get_headers(handler):
|
||||
@@ -73,6 +76,15 @@ def random_encoding(handler):
|
||||
handler.wfile.write('0\r\n\r\n'.encode('utf-8'))
|
||||
|
||||
|
||||
@TestHandler.handler('POST', '/status/msg')
|
||||
def status_custom_msg(handler):
|
||||
content_len = int(handler.headers.get('content-length', 0))
|
||||
post_body = handler.rfile.read(content_len).decode()
|
||||
|
||||
handler.send_response(200, post_body)
|
||||
handler.end_headers()
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def http_server():
|
||||
"""A custom HTTP server implementation for our tests, that is
|
||||
|
||||
Reference in New Issue
Block a user