-
Notifications
You must be signed in to change notification settings - Fork 113
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
feature request: system proxy support #407
Comments
I think if we support |
sure, and use proxy config in global # in .gitignore
[https]
proxy = http://127.0.0.1:7890
[http]
proxy = http://127.0.0.1:7890 |
another way to provide proxy that I have seen is to set the |
No, but I mean that we could support that or use a library that does |
We use node-fetch for git-node-land (not sure about other commands) so at least it should be fairly doable by using one of the proxy agent implementations on npm with https://github.com/node-fetch/node-fetch#custom-agent in this abstraction that most of our HTTP requests go through But be aware that users need to configure the proxy setting for the git repository so that git picks it up and that may be tricky, especially for people who use SSH instead of HTTPS (then the setting needs to go to the SSH config, which is global), to make git-node support all of them automatically, we may have to change the setting of the entire system. Anyway I'd say PRs to make the option effective for our own HTTP requests are welcomed. We could just prompt the users that they need to do something about their own git/ssh configs for everything to go through the proxy and leave it at that at least. |
I code a simple implementation for self-use, later I will finish the PR diff --git a/lib/request.js b/lib/request.js
index 3aff3e9..d5cccb5 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -1,13 +1,15 @@
'use strict';
const fetch = require('node-fetch');
+const HttpsProxyAgent = require('https-proxy-agent');
const fs = require('fs');
const path = require('path');
const { CI_DOMAIN } = require('./ci/ci_type_parser');
class Request {
- constructor(credentials) {
+ constructor(credentials, proxyUrl) {
this.credentials = credentials;
+ this.proxyAgent = new HttpsProxyAgent('http://127.0.0.1:7890');
}
loadQuery(file) {
@@ -16,6 +18,7 @@ class Request {
}
async text(url, options = {}) {
+ options.agent = this.proxyAgent;
if (url.startsWith(`https://${CI_DOMAIN}`)) {
options.headers = options.headers || {};
Object.assign(options.headers, this.getJenkinsHeaders());
@@ -24,6 +27,7 @@ class Request {
}
async json(url, options = {}) {
+ options.agent = this.proxyAgent;
options.headers = options.headers || {};
options.headers.Accept = 'application/json';
if (url.startsWith(`https://${CI_DOMAIN}`)) {
@@ -65,6 +69,7 @@ class Request {
}
const url = 'https://api.github.com/graphql';
const options = {
+ agent: this.proxyAgent,
method: 'POST',
headers: {
Authorization: `Basic ${githubCredentials}`, |
My PC have to use proxy to access GitHub (you know why)
and I will take some time to handle this
The text was updated successfully, but these errors were encountered: