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
fix(language-server): use https and http proxy agent to make fetcher … #302
Conversation
…work behind proxy Added custom agent to fetcher / node-fetch to be able to GET ui5-model behind a proxy (e.g. corporate proxy). Therefore look at environment variables HTTPS_PROXY, HTTP_PROXY and NO_PROXY and respect them depending on request url. fix SAP#285
Thanks for making this PR @ndrsg 🍰 ReviewCustom User Agent vs using a different http[s] library
Logic structure.Could we avoid mixing up the building of the userAgent and the let fetchOptions = {};
if (process.env["http_proxy"] && otherCondition) {
fetchOptions.agent = new HttpProxyAgent(process.env["HTTP_PROXY"]);
}
else if (HTTPS_CONDITION) {
fetchOptions.agent = new HttpsProxyAgent(process.env["HTTPS_PROXY"]);
}
// only call `fetch` once.
fetch(url, fetchOptions) Basically this would enable us to extract the new logic to a separate function which could be useful:
Console usageI wonder if we should keep these or remove these. ESLint errorsYou can tell eslint to ignore errors in certain lines, probably something like:
See relevant docs: |
Hi, I agree with @bd82.
|
Hello @bd82 and @tal-sapan , thanks for your review, I want to reply to some points:
Yes I considered, but thought better not adding an additional dependency. If you think its a better option to use, e.g. https://github.com/axios/axios , i can also try to integrate it.
Yes that's true, i forgot about JSON Case Sensitivity. Extracting functionality to another function might be a good idea in general. fetch allows to pass a function that returns an agent instead of passing an agent directly.
Sorry, I'm not sure if I understand that correctly, can you give me an example here?
Okay. |
Hi @ndrsg,
This library looks good to me and seems to handle more cases (for example, both lowercase and uppercase proxy env vars, no_proxy env var that contains
Sure, I'll explain in more detail.
|
Generally it is better to add a new dependency for this due to possible edge cases complexity. Please note that I guess it would suffice to handle all upper or all lower case on linux (HTTP_PROXY vs http_proxy) |
I found a hack resolved this for me in vscode while working on other related issue. Step 1: C:>netsh winhttp set proxy http://172.16.0.38:808 bypass-list="localhost;127.0.0.1" Step 2: Launch VSCode from command with Step 3: Optional confirm proxy in VScode terminal with Step 4: Confirm proxy is working in VScode terminal with Now try code-completion and inline documentation etc. Credit goes to @petermuessig |
Working behind a proxy in Node project is a challenge. Not all module consider the process env proxy settings when making http calls. So try the hack shared above, and your ref. module may be using env proxy settings before http calls. |
…work behind proxy
Added custom agent to fetcher / node-fetch to be able to GET ui5-model behind a proxy (e.g.
corporate proxy). Therefore look at environment variables HTTPS_PROXY, HTTP_PROXY and NO_PROXY and
respect them depending on request url.
I'm passing agent as any, because of incompatibility of agent-base typings:
TooTallNate/proxy-agents#108
fix #285