httpie/cli

Trim trailing empty lines from CLI output

Opened this issue · 1 comments

Checklist

  • I've searched for similar feature requests.

Enhancement request

The output from the CLI seems to always include 2 trailing empty lines. Could they be removed?

Example command: $ https google.com

Current output:

HTTP/1.1 301 Moved Permanently
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Cache-Control: private, max-age=2592000
Content-Length: 220
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-qWBSXxuQK80KB3NcDHBMJw' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
Content-Type: text/html; charset=UTF-8
Date: Thu, 21 Dec 2023 11:01:33 GMT
Expires: Thu, 21 Dec 2023 11:01:33 GMT
Location: https://www.google.com/
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
Set-Cookie: CONSENT=PENDING+017; expires=Sat, 20-Dec-2025 11:01:33 GMT; path=/; domain=.google.com; Secure
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 0

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>


The output I would like:

HTTP/1.1 301 Moved Permanently
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Cache-Control: private, max-age=2592000
Content-Length: 220
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-qWBSXxuQK80KB3NcDHBMJw' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
Content-Type: text/html; charset=UTF-8
Date: Thu, 21 Dec 2023 11:01:33 GMT
Expires: Thu, 21 Dec 2023 11:01:33 GMT
Location: https://www.google.com/
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
Set-Cookie: CONSENT=PENDING+017; expires=Sat, 20-Dec-2025 11:01:33 GMT; path=/; domain=.google.com; Secure
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 0

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>

So exactly the same, and still with an empty line for padding between sections like headers and body, but without the 2 trailing empty lines.


Problem it solves

Would give a shorter output. This means there would be a shorter distance to scroll up to some output, and in some cases there would be no need to scroll at all, since more actual output could fit in the window.


Additional information, screenshots, or code examples

Version: 3.2.1
OS: Ubuntu 23.10

MESSAGE_SEPARATOR = '\n\n'
MESSAGE_SEPARATOR_BYTES = MESSAGE_SEPARATOR.encode()

These lines append two newlines at the end of the output. I also thinks that it should append only a single newline.