AnWeber / vscode-httpyac

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac
MIT License
235 stars 20 forks source link

feature request: support socks proxy #91

Closed ex-nerd closed 2 years ago

ex-nerd commented 2 years ago

I use a socks proxy (via ssh) to communicate with servers inside of a VPC. It would be nice if this could be specified either directly in the .http file config, or via examples for how to set this up with an inline script.

AnWeber commented 2 years ago

You could solve this using socks-proxy-agent (see https://github.com/sindresorhus/got/issues/7#issuecomment-535828261). Can you test the following if it works for you.

const SocksProxyAgent = require('socks-proxy-agent'); const tunnel = new SocksProxyAgent({ host: 'br41.nordvpn.com', userId: 'your-name@gmail.com', password: 'abcdef12345124' }); request.agent = tunnel;

}}



It is important to set `http.proxy=''` and `http.proxySupport=off` in vscode. Using [httpyac cli](https://www.npmjs.com/package/httpyac) it is not needed. VSCode is really tricky to use with proxy support.

If this works, I can consider adding this to httpyac. I can't really test it unfortunately.
AnWeber commented 2 years ago

Since I don't run a SockJS proxy I can't test it unfortunately. If there is still a need for the feature, please just reopen the issue.

ex-nerd commented 2 years ago

I still haven't had time to give this a try. I got as far as pasting the code into my test script and then distracted. I think I need to figure out where the node is that httpyac runs, since I don't have a "system" node to work with.

No need for any special proxy software, though. you can just open one via ssh with ssh -D 1080 user@host and then set your proxy to localhost:1080.

AnWeber commented 2 years ago

Thanks for the info. Will try the ssh approach:-)

AnWeber commented 2 years ago

I have now tried the integration of the socks proxy. I also tested it using an SSH server, but if my test setup was correct, I am not 100% sure. Could you please test it once after release and give feedback? Thanks.

# @proxy socks://127.0.0.1:1080

GET https://httpbin.org/json HTTP/1.1

You can test the change with v4.9.0.

ex-nerd commented 2 years ago

Sorry for such a long delay in replying.. I tested your code above in 4.9.1 with and without that # and the query runs successfully no matter what value I put in for the proxy. I would expect some sort of timeout if the proxy port/URL I give doesn't exist (or is malformed if I use something like # @proxy socks://127.0.0.1:abcd)

I also tested it with servers I know require a proxy, and the requests time out, which suggests the proxy isn't activating.

AnWeber commented 2 years ago

Phew, then I need help. I tested it with the Kubernetes Api, which is only accessible via Jumphost. I have performed the following steps:

  1. open SSH Proxy
    ssh -D 1111 k8sprod@k8smaintenance.prod.int.example.de
  2. created http request
    # @proxy socks://127.0.0.1:1111
    # @noRejectUnauthorized
    GET https://10.1.26.1:6443/openapi/v2

In the browser, the URL is not reachable. Without # @proxy socks://127.0.0.1:1111 the URL is not reachable. With # @proxy socks://127.0.0.1:1111 it is reachable. Did I miss something?

AnWeber commented 2 years ago

Please add a more detailed description of how I can recreate the problem. I will close the ticket until then, because I currently do not know how to follow up the problem. thanks.