Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support beautification of HTTP 100 responses. #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions curlish.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,20 +553,25 @@ def _walk(obj, indentation, inline=False, w=sys.stdout.write):

def beautify_curl_output(iterable, hide_headers, hide_jsonp=False):
"""Parses curl output and adds colors and reindents as necessary."""
continuing = False
json_body = False
might_be_javascript = False
has_colors = is_color_terminal()

# Headers
for line in iterable:
if has_colors and re.search(r'^HTTP/', line):
if re.search('HTTP/\d+.\d+ [45]\d+', line):
color = get_color('statusline_error')
else:
color = get_color('statusline_ok')
if not hide_headers:
if re.search(r'^HTTP/', line):
if re.search('HTTP/\d+.\d+\s+100', line):
continuing = True
elif continuing:
continuing = False
if has_colors and not hide_headers:
if re.search('HTTP/\d+.\d+\s+[45]\d+', line):
color = get_color('statusline_error')
else:
color = get_color('statusline_ok')
sys.stdout.write(color + line + ANSI_CODES['reset'])
continue
continue
if re.search(r'^Content-Type:\s*(text/javascript|application/(.+?\+)?json)\s*(?i)', line):
json_body = True
if 'javascript' in line:
Expand All @@ -583,7 +588,7 @@ def beautify_curl_output(iterable, hide_headers, hide_jsonp=False):
else:
sys.stdout.write(line)
sys.stdout.flush()
if line == '\r\n':
if line == '\r\n' and not continuing:
break

# JSON Body. Do not reindent if we have headers and are piping
Expand Down