Chris911 / Ask-Stack-Atom

Ask Stack Overflow for Atom
https://atom.io/packages/ask-stack
MIT License
124 stars 22 forks source link

Proxy support #9

Closed pkazmier closed 10 years ago

pkazmier commented 10 years ago

Please add proxy support to Ask Stack for those of us who are stuck behind great corporate firewalls ...

Chris911 commented 10 years ago

This feature request seems more appropriate for Atom itself and not for this particular package. Feel free to open an issue in their repo.

pkazmier commented 10 years ago

Atom does support working behind a proxy. They honor the http_proxy environment variable. Your use of https.request does not, however, as it assumes a direct connection.

Chris911 commented 10 years ago

I can take a look later. So basically you are asking to check for the presence of the http_proxy env variable before making the request and it use for the request. What about the port? Is http_proxy a common practice? I don't want to add support for this if it could break regular users that have the env variable set "by mistake" to favor a few who actually use it.

Re-opening for now while I investigate.

pkazmier commented 10 years ago

Yes, http_proxy is a well known environment variable honored by many tools. The format of the value is [protocol://]<host>[:port]. For example, proxy.example.com:8000. If a user has this variable defined, then any requests should be made via the proxy server. I'm not very familiar with the node landscape, but after a quick google, it looks like there are essentially two options:

  1. You can manually test for the proxy environment variable and then issue your request to the proxy passing the path to the real URL, or
  2. You can use a package with built-in proxy support. This seemed to be the most referenced package in my quick search: request

Thanks, Pete

Chris911 commented 10 years ago

I'll try to make the switch to request. Seems like the easiest solution.

Chris911 commented 10 years ago

Hopefully https://github.com/Chris911/Ask-Stack-Atom/commit/35a505a146fcf16c3454f705a440f0587e405625 should do it. The request library supposedly supports http_proxy so it should fix your issue. Also got rid of the gzip decompressing code which is now handled by the library (good stuff).

I just updated the package to v0.0.7 let me know if it works out for you.

pkazmier commented 10 years ago

It does not look like request supports the automatic use of http_proxy as a packet capture on my local machine confirms it's still trying to directly connect to stackexchange without the use of my defined proxy. I think you'll need to add this line before your call to request to set the proxy if it is defined.

options.proxy = process.env.http_proxy if process.env.http_proxy?
Chris911 commented 10 years ago

I'll try that. Kinda hard for me to test because I don't use a proxy and don't really want to start playing with that. When you download the package the code is available at ~/.atom/packages so if you want to try and add that line and submit a pull request it would really help.