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

Respect HTTP_PROXY and HTTPS_PROXY #1081

Closed
adanilev opened this issue Apr 13, 2020 · 5 comments · Fixed by #1234
Closed

Respect HTTP_PROXY and HTTPS_PROXY #1081

adanilev opened this issue Apr 13, 2020 · 5 comments · Fixed by #1234

Comments

@adanilev
Copy link
Contributor

adanilev commented Apr 13, 2020

User story.
As a user running behind a corporate proxy, I can use Spectral from JS, so that I can reap its benefits.

Is your feature request related to a problem?
Spectral doesn't work behind a corporate proxy if you're not using the CLI.

Describe the solution you'd like
Spectral should try to use a proxy when it is instantiated from code as documented here and not only when it's called via CLI.

AFAIK, HTTPS_PROXY, HTTP_PROXY and their lowercase cousins are standard environment variables for setting proxies. Many people will already have them set if they are using a proxy. In order, Spectral should try to use:

  • HTTPS_PROXY
  • https_proxy
  • HTTP_PROXY
  • http_proxy
  • PROXY
  • proxy

Additional context
I'm calling Spectral within a TS project and calls to loadRuleset were taking > 2 minutes because requests to http://json-schema.org were timing out when I extended the spectral:oas ruleset.

Happy to try my hand at a PR if you agree with the proposed solution?

@nulltoken
Copy link
Contributor

Happy to try my hand at a PR if you agree with the proposed solution?

That sounds like a valid proposal to me. @P0lip Would you 👍 as well?

@adanilev Potentially relevant (for context):

@nulltoken
Copy link
Contributor

@adanilev On second thought, provided @P0lip agrees with the initial idea, I wonder if we shouldn't make the Spectral library unaware of that selection process and those ENV variables.

The counter proposal would be to extend the Spectral ctor parameters so that it accepts one optional proxy param.

If a "which better ENV variable should I use to pick as the proxy address" process should exist, it would be move up in the cli and exported for potential reuse.

This way:

  • We make Spectral agnostic of the proxy selection process
  • From a TS project standpoint
    • leveraging Spectral would only be a matter of passing a param while building the Spectral instance
    • optionally could leverage the exported proxy selection process from Spectral/cli namespace

Thoughts?

@P0lip
Copy link
Contributor

P0lip commented Apr 13, 2020

This is a tricky problem, as we do need to keep in mind the browser usage.
If I am not mistaken proxy-agent is very unlikely to work in the context of browser unless we correctly shim plenty of modules, so we cannot really use it globally.
This is the primary reason we made it CLI-only, as we cannot really guarantee it will work everywhere.

The second idea @nulltoken proposed sounds OK.
We can do it that way, as this would move the responsibility of providing the proper solution to the consumer side.

@nulltoken
Copy link
Contributor

Happy to try my hand at a PR if you agree with the proposed solution

@adanilev Would you still be open to move this farther?

@adanilev
Copy link
Contributor Author

@nulltoken, yes, for sure. Will aim to submit something soon, apologies for the slowness. I'll work on your second option - passing a proxy param to the Spectral constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants