ducaale / xh

Friendly and fast tool for sending HTTP requests
MIT License
5.49k stars 96 forks source link

HTTPie feature parity checklist #4

Open ducaale opened 3 years ago

ducaale commented 3 years ago
abner commented 3 years ago

httpie uses the value of environment variable REQUESTS_CA_BUNDLE to verify if it is present. Would be nice if xh uses it too.

ducaale commented 3 years ago

It doesn't seem to be mentioned in the docs but it is, in fact, something that HTTPie supports.

The library we use for parsing command-line arguments supports falling back to an env variable so this should be an easy one to implement. Would like to create a PR for it?

Edit: this has been implemented in https://github.com/ducaale/xh/pull/146

blyxxyz commented 3 years ago

requests checks both REQUESTS_CA_BUNDLE and CURL_CA_BUNDLE, so perhaps we should also look for both.

ducaale commented 3 years ago

So this means we can no longer use the nice API that structopt offers. If that is the case, we should manually check for those env variables inside the from_iter_safe() function and then set cli.verify from there.

vlcinsky commented 2 years ago

xh does not process query parameter read from file as httpie does:

Prepare a file with value for query parameter

First we create a file with a value to use:

$ echo "filed-value" > arg.value

Use http, reading query parameter from the file

Then using http we ask to use this value read from the file for query parameter arg:

$ http https://httpbin.org/get arg==@arg.value
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 342
Content-Type: application/json
Date: Wed, 05 Oct 2022 23:11:13 GMT
Server: gunicorn/19.9.0

{
    "args": {
        "arg": "filed-value"
    },
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Host": "httpbin.org",
        "User-Agent": "HTTPie/3.2.1",
        "X-Amzn-Trace-Id": "Root=1-633e0f11-6265bd27088a85585daa3a5d"
    },
    "origin": "185.151.252.82",
    "url": "https://httpbin.org/get?arg=filed-value"
}

As we can see, the response report the value for arg is "filed-value" as expected.

Use xh to read the query parameter from the file - fails with using the file name

Now try the same with xh:

$ xh https://httpbin.org/get arg==@arg.value
HTTP/2.0 200 OK
access-control-allow-credentials: true
access-control-allow-origin: *
content-length: 343
content-type: application/json
date: Wed, 05 Oct 2022 23:11:31 GMT
server: gunicorn/19.9.0

{
    "args": {
        "arg": "@arg.value"
    },
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate, br",
        "Host": "httpbin.org",
        "User-Agent": "xh/0.16.1",
        "X-Amzn-Trace-Id": "Root=1-633e0f23-1fbbb3d05048db3a7649a622"
    },
    "origin": "185.151.252.82",
    "url": "https://httpbin.org/get?arg=%40arg.value"
}

As can be seen, it did not read the value from the file, instead it used value of the file itself.

ducaale commented 2 years ago

Thanks, @vlcinsky. I have now included this in the feature compatibility checklist.

For reference, https://github.com/httpie/httpie/pull/1225 is the PR that added support for reading header and query string values from a file.

vlcinsky commented 2 years ago

@ducaale great.

Just a note: http does urlencoding for the values read from the file before putting it into final url string.