mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Github: add ability to disable proxy
This commit is contained in:
@@ -135,7 +135,7 @@ public class GithubApiUtil {
|
||||
@Nullable final String requestBody,
|
||||
@NotNull final Collection<Header> headers,
|
||||
@NotNull final HttpVerb verb) throws IOException {
|
||||
HttpClient client = getHttpClient(auth.getBasicAuth());
|
||||
HttpClient client = getHttpClient(auth.getBasicAuth(), auth.isUseProxy());
|
||||
return GithubSslSupport.getInstance()
|
||||
.executeSelfSignedCertificateAwareRequest(client, uri, new ThrowableConvertor<String, HttpMethod, IOException>() {
|
||||
@Override
|
||||
@@ -173,7 +173,7 @@ public class GithubApiUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static HttpClient getHttpClient(@Nullable GithubAuthData.BasicAuth basicAuth) {
|
||||
private static HttpClient getHttpClient(@Nullable GithubAuthData.BasicAuth basicAuth, boolean useProxy) {
|
||||
final HttpClient client = new HttpClient();
|
||||
HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
|
||||
params.setConnectionTimeout(CONNECTION_TIMEOUT); //set connection timeout (how long it takes to connect to remote host)
|
||||
@@ -182,7 +182,7 @@ public class GithubApiUtil {
|
||||
client.getParams().setContentCharset("UTF-8");
|
||||
// Configure proxySettings if it is required
|
||||
final HttpConfigurable proxySettings = HttpConfigurable.getInstance();
|
||||
if (proxySettings.USE_HTTP_PROXY && !StringUtil.isEmptyOrSpaces(proxySettings.PROXY_HOST)) {
|
||||
if (useProxy && proxySettings.USE_HTTP_PROXY && !StringUtil.isEmptyOrSpaces(proxySettings.PROXY_HOST)) {
|
||||
client.getHostConfiguration().setProxy(proxySettings.PROXY_HOST, proxySettings.PROXY_PORT);
|
||||
if (proxySettings.PROXY_AUTHENTICATION) {
|
||||
client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxySettings.PROXY_LOGIN,
|
||||
|
||||
@@ -269,7 +269,7 @@ public class GithubRepository extends BaseRepositoryImpl {
|
||||
}
|
||||
|
||||
private GithubAuthData getAuthData() {
|
||||
return GithubAuthData.createTokenAuth(getUrl(), getToken());
|
||||
return GithubAuthData.createTokenAuth(getUrl(), getToken(), isUseProxy());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,15 +36,19 @@ public class GithubAuthData {
|
||||
@NotNull private final String myHost;
|
||||
@Nullable private final BasicAuth myBasicAuth;
|
||||
@Nullable private final TokenAuth myTokenAuth;
|
||||
private final boolean myUseProxy;
|
||||
|
||||
|
||||
private GithubAuthData(@NotNull AuthType authType,
|
||||
@NotNull String host,
|
||||
@Nullable BasicAuth basicAuth,
|
||||
@Nullable TokenAuth tokenAuth) {
|
||||
@Nullable TokenAuth tokenAuth,
|
||||
boolean useProxy) {
|
||||
myAuthType = authType;
|
||||
myHost = host;
|
||||
myBasicAuth = basicAuth;
|
||||
myTokenAuth = tokenAuth;
|
||||
myUseProxy = useProxy;
|
||||
}
|
||||
|
||||
public static GithubAuthData createAnonymous() {
|
||||
@@ -52,15 +56,19 @@ public class GithubAuthData {
|
||||
}
|
||||
|
||||
public static GithubAuthData createAnonymous(@NotNull String host) {
|
||||
return new GithubAuthData(AuthType.ANONYMOUS, host, null, null);
|
||||
return new GithubAuthData(AuthType.ANONYMOUS, host, null, null, true);
|
||||
}
|
||||
|
||||
public static GithubAuthData createBasicAuth(@NotNull String host, @NotNull String login, @NotNull String password) {
|
||||
return new GithubAuthData(AuthType.BASIC, host, new BasicAuth(login, password), null);
|
||||
return new GithubAuthData(AuthType.BASIC, host, new BasicAuth(login, password), null, true);
|
||||
}
|
||||
|
||||
public static GithubAuthData createTokenAuth(@NotNull String host, @NotNull String token) {
|
||||
return new GithubAuthData(AuthType.TOKEN, host, null, new TokenAuth(token));
|
||||
return new GithubAuthData(AuthType.TOKEN, host, null, new TokenAuth(token), true);
|
||||
}
|
||||
|
||||
public static GithubAuthData createTokenAuth(@NotNull String host, @NotNull String token, boolean useProxy) {
|
||||
return new GithubAuthData(AuthType.TOKEN, host, null, new TokenAuth(token), useProxy);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -83,6 +91,10 @@ public class GithubAuthData {
|
||||
return myTokenAuth;
|
||||
}
|
||||
|
||||
public boolean isUseProxy() {
|
||||
return myUseProxy;
|
||||
}
|
||||
|
||||
public static class BasicAuth {
|
||||
@NotNull private final String myLogin;
|
||||
@NotNull private final String myPassword;
|
||||
|
||||
Reference in New Issue
Block a user