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

Unable to See Status Code in Output #1300

Closed
EarthCitizen opened this issue Feb 19, 2022 · 5 comments · Fixed by #1301
Closed

Unable to See Status Code in Output #1300

EarthCitizen opened this issue Feb 19, 2022 · 5 comments · Fixed by #1301
Labels
bug Something isn't working

Comments

@EarthCitizen
Copy link

EarthCitizen commented Feb 19, 2022

Checklist

  • [ X] I've searched for similar issues.
  • [ X] I'm using the latest version of HTTPie.

Minimal reproduction code and steps

  1. Run local web service that returns 401 for endpoint :8080/get-values
  2. Run HTTPie against endpoint

Current result

Curl output:

$ curl -v 'http://localhost:8080/get-values'       
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /get-values HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.1
> Accept: */*
> 
< HTTP/1.1 401 
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Sat, 19 Feb 2022 00:01:22 GMT
< 
* Connection #0 to host localhost left intact
* <body redacted>

HTTPie output:

$ http --verbose ':8080/get-values' 
GET /get-values HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/3.0.2



HTTP/1.1 
Connection: keep-alive
Content-Type: application/json
Date: Sat, 19 Feb 2022 00:02:54 GMT
Keep-Alive: timeout=60
Transfer-Encoding: chunked
<body redacted>

Expected result

Expecting to see HTTP/1.1 401 instead of just HTTP/1.1 .

Debug output

Please re-run the command with --debug, then copy the entire command & output and paste both below:

$ http --debug ':8080/get-values'
HTTPie 3.0.2
Requests 2.27.1
Pygments 2.11.2
Python 3.10.2 (main, Feb  2 2022, 08:42:42) [Clang 13.0.0 (clang-1300.0.29.3)]
/usr/local/Cellar/httpie/3.0.2/libexec/bin/python3.10
Darwin 20.6.0

<Environment {'as_silent': <function Environment.as_silent at 0x10d7d0f70>,
 'colors': 256,
 'config': {'default_options': ['--style=fruity']},
 'config_dir': PosixPath('/Users/<redacted>/.config/httpie'),
 'devnull': <property object at 0x10d7c4cc0>,
 'is_windows': False,
 'log_error': <function Environment.log_error at 0x10d7d1000>,
 'program_name': 'http',
 'stderr': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>,
 'stderr_isatty': True,
 'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
 'stdin_encoding': 'utf-8',
 'stdin_isatty': True,
 'stdout': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>,
 'stdout_encoding': 'utf-8',
 'stdout_isatty': True}>

<PluginManager {'adapters': [],
 'auth': [<class 'httpie.plugins.builtin.BasicAuthPlugin'>,
          <class 'httpie.plugins.builtin.DigestAuthPlugin'>,
          <class 'httpie.plugins.builtin.BearerAuthPlugin'>],
 'converters': [],
 'formatters': [<class 'httpie.output.formatters.headers.HeadersFormatter'>,
                <class 'httpie.output.formatters.json.JSONFormatter'>,
                <class 'httpie.output.formatters.xml.XMLFormatter'>,
                <class 'httpie.output.formatters.colors.ColorFormatter'>]}>

>>> requests.request(**{'auth': None,
 'data': RequestJSONDataDict(),
 'headers': <HTTPHeadersDict('User-Agent': b'HTTPie/3.0.2')>,
 'method': 'get',
 'params': <generator object MultiValueOrderedDict.items at 0x10da93450>,
 'url': 'http://localhost:8080/get-values'})

HTTP/1.1 
Connection: keep-alive
Content-Type: application/json
Date: Sat, 19 Feb 2022 00:05:16 GMT
Keep-Alive: timeout=60
Transfer-Encoding: chunked

<body redacted>
@EarthCitizen EarthCitizen added bug Something isn't working new Needs triage. Comments are welcome! labels Feb 19, 2022
@isidentical
Copy link
Contributor

Hey @EarthCitizen! I can't seem to reproduce your problem locally with pie.dev/status/401:

$ http pie.dev/status/401                

HTTP/1.1 401 Unauthorized
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
CF-Cache-Status: DYNAMIC
CF-RAY: 6e1666df9854506f-IST
Connection: keep-alive
Content-Length: 0
Date: Tue, 22 Feb 2022 07:11:42 GMT
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=jIQvWvDlmjODsJJ9KskFBgjGCj8C%2FEWfor2vtcajcyNx36NEkDzcQF0BcNBpcTEUcFVswHvxYfZaJIyPlSBFyaMu81PGM51CpX36RWBkZUcSxMOIPvOkN8IY"}],"group":"cf-nel","max_age":604800}
Server: cloudflare
WWW-Authenticate: Basic realm="Fake Realm"
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

If it is possible, would you mind sharing the underlying server code that returns this response? This was, we could have a reliable reproducer to test and hopefully fix this issue.

@isidentical isidentical added awaiting-response and removed new Needs triage. Comments are welcome! labels Feb 22, 2022
@EarthCitizen
Copy link
Author

EarthCitizen commented Feb 22, 2022

@isidentical

I did some additional testing. Spring Boot does not send a reason phrase on the status line of the response:

Spring Boot raw status line:

HTTP/1.1 404

Which in HTTPie results in:

$ http ':8080/not-exists'
HTTP/1.1 
Connection: keep-alive
Content-Type: application/json
Date: Tue, 22 Feb 2022 22:10:52 GMT
Keep-Alive: timeout=60
Transfer-Encoding: chunked
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers

{
    "error": "Not Found",
    "message": "No message available",
    "path": "/not-exists",
    "status": 404,
    "timestamp": "2022-02-22T22:10:52.926+00:00"
}

When I do a similar test with Python http.server, HTTPie does show the status code:

Python http.server raw status line:

HTTP/1.0 400 Bad Request

Python http.server:

$ http 'http://localhost:8080'
HTTP/1.0 400 Bad Request
Content-type: application/json
Date: Tue, 22 Feb 2022 22:05:19 GMT
Server: BaseHTTP/0.6 Python/3.9.10

{}

So the issue here would seem to be that HTTPie fails to display a status code when the status line lacks a reason phrase.

@EarthCitizen
Copy link
Author

EarthCitizen commented Feb 22, 2022

For an example Spring Boot project:

https://start.spring.io/#!type=gradle-project&language=java&platformVersion=2.6.3&packaging=jar&jvmVersion=11&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies=web

Click "Generate" on that page, which will download a zip. In that project folder, run this to start the server:

./gradlew bootRun

This will start a server on port 8080, which should give 404 for any request as no endpoints defined.

@jkbrzt
Copy link
Member

jkbrzt commented Feb 22, 2022

@isidentical I think this was introduced with the addition of the Pie theme. Please see #811.

@isidentical
Copy link
Contributor

@EarthCitizen thanks a lot for sharing the root cause. From that, I was able to make a reproducer via Python's http.server to be used in tests. @jakubroztocil you are right! The handling of HTTP status line in our own lexer (the one that we use for custom themes, e.g anything beside auto) changed when we introduced the custom highlighter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants