protected void InitProxies() { TotalOperations += Proxies.Length; if (Proxies.Length > 0) { var selector = new ProxySelector(); foreach (var proxyString in Proxies) { var proxy = Proxy.FromString(proxyString); RequestFactory = HttpRequestFactory.CreateProxyFactory(proxy); if (TestProxy()) { Log.InfoFormat("Proxy added, Proxy={0}", proxy); selector.Add(proxy); } else { Log.InfoFormat("Proxy failed, Proxy={0}", proxy); } OnProgress(); } if (selector.ProxyCount == 0) { Log.Info("No poxies pass test. Fail."); Thread.CurrentThread.Abort(); } RequestFactory = HttpRequestFactory.CreateProxySelector(selector); } }
/// <summary>Determine the proxy server (if any) needed to obtain a URL.</summary> /// <remarks>Determine the proxy server (if any) needed to obtain a URL.</remarks> /// <param name="proxySelector">proxy support for the caller.</param> /// <param name="u">location of the server caller wants to talk to.</param> /// <returns>proxy to communicate with the supplied URL.</returns> /// <exception cref="Sharpen.ConnectException"> /// the proxy could not be computed as the supplied URL could not /// be read. This failure should never occur. /// </exception> public static Proxy ProxyFor(ProxySelector proxySelector, Uri u) { try { return(proxySelector.Select(u.ToURI())[0]); } catch (URISyntaxException e) { ConnectException err; err = new ConnectException(MessageFormat.Format(JGitText.Get().cannotDetermineProxyFor , u)); Sharpen.Extensions.InitCause(err, e); throw err; } }
/// <exception cref="System.NotSupportedException"></exception> protected internal TransportHttp(Repository local, URIish uri) : base(local, uri) { try { string uriString = uri.ToString(); if (!uriString.EndsWith("/")) { //$NON-NLS-1$ uriString += "/"; } //$NON-NLS-1$ baseUrl = new Uri(uriString); objectsUrl = new Uri(baseUrl, "objects/"); } catch (UriFormatException e) { //$NON-NLS-1$ throw new NotSupportedException(MessageFormat.Format(JGitText.Get().invalidURL, uri ), e); } http = local.GetConfig().Get(HTTP_KEY); proxySelector = ProxySelector.GetDefault(); }
public SystemDefaultRoutePlanner(ProxySelector proxySelector) : this(null, proxySelector ) { }
public SystemDefaultRoutePlanner(SchemePortResolver schemePortResolver, ProxySelector proxySelector) : base(schemePortResolver) { this.proxySelector = proxySelector != null ? proxySelector : ProxySelector.GetDefault (); }
public static void setDefault(ProxySelector prm1) { }
public virtual CloseableHttpClient Build() { // Create main request executor HttpRequestExecutor requestExec = this.requestExec; if (requestExec == null) { requestExec = new HttpRequestExecutor(); } HttpClientConnectionManager connManager = this.connManager; if (connManager == null) { LayeredConnectionSocketFactory sslSocketFactory = this.sslSocketFactory; if (sslSocketFactory == null) { string[] supportedProtocols = systemProperties ? Split(Runtime.GetProperty("https.protocols" )) : null; string[] supportedCipherSuites = systemProperties ? Split(Runtime.GetProperty("https.cipherSuites" )) : null; X509HostnameVerifier hostnameVerifier = this.hostnameVerifier; if (hostnameVerifier == null) { hostnameVerifier = SSLConnectionSocketFactory.BrowserCompatibleHostnameVerifier; } if (sslcontext != null) { sslSocketFactory = new SSLConnectionSocketFactory(sslcontext, supportedProtocols, supportedCipherSuites, hostnameVerifier); } else { if (systemProperties) { sslSocketFactory = new SSLConnectionSocketFactory((SSLSocketFactory)SSLSocketFactory .GetDefault(), supportedProtocols, supportedCipherSuites, hostnameVerifier); } else { sslSocketFactory = new SSLConnectionSocketFactory(SSLContexts.CreateDefault(), hostnameVerifier ); } } } PoolingHttpClientConnectionManager poolingmgr = new PoolingHttpClientConnectionManager (RegistryBuilder.Create <ConnectionSocketFactory>().Register("http", PlainConnectionSocketFactory .GetSocketFactory()).Register("https", sslSocketFactory).Build()); if (defaultSocketConfig != null) { poolingmgr.SetDefaultSocketConfig(defaultSocketConfig); } if (defaultConnectionConfig != null) { poolingmgr.SetDefaultConnectionConfig(defaultConnectionConfig); } if (systemProperties) { string s = Runtime.GetProperty("http.keepAlive", "true"); if (Sharpen.Runtime.EqualsIgnoreCase("true", s)) { s = Runtime.GetProperty("http.maxConnections", "5"); int max = System.Convert.ToInt32(s); poolingmgr.SetDefaultMaxPerRoute(max); poolingmgr.SetMaxTotal(2 * max); } } if (maxConnTotal > 0) { poolingmgr.SetMaxTotal(maxConnTotal); } if (maxConnPerRoute > 0) { poolingmgr.SetDefaultMaxPerRoute(maxConnPerRoute); } connManager = poolingmgr; } ConnectionReuseStrategy reuseStrategy = this.reuseStrategy; if (reuseStrategy == null) { if (systemProperties) { string s = Runtime.GetProperty("http.keepAlive", "true"); if (Sharpen.Runtime.EqualsIgnoreCase("true", s)) { reuseStrategy = DefaultConnectionReuseStrategy.Instance; } else { reuseStrategy = NoConnectionReuseStrategy.Instance; } } else { reuseStrategy = DefaultConnectionReuseStrategy.Instance; } } ConnectionKeepAliveStrategy keepAliveStrategy = this.keepAliveStrategy; if (keepAliveStrategy == null) { keepAliveStrategy = DefaultConnectionKeepAliveStrategy.Instance; } AuthenticationStrategy targetAuthStrategy = this.targetAuthStrategy; if (targetAuthStrategy == null) { targetAuthStrategy = TargetAuthenticationStrategy.Instance; } AuthenticationStrategy proxyAuthStrategy = this.proxyAuthStrategy; if (proxyAuthStrategy == null) { proxyAuthStrategy = ProxyAuthenticationStrategy.Instance; } UserTokenHandler userTokenHandler = this.userTokenHandler; if (userTokenHandler == null) { if (!connectionStateDisabled) { userTokenHandler = DefaultUserTokenHandler.Instance; } else { userTokenHandler = NoopUserTokenHandler.Instance; } } ClientExecChain execChain = new MainClientExec(requestExec, connManager, reuseStrategy , keepAliveStrategy, targetAuthStrategy, proxyAuthStrategy, userTokenHandler); execChain = DecorateMainExec(execChain); HttpProcessor httpprocessor = this.httpprocessor; if (httpprocessor == null) { string userAgent = this.userAgent; if (userAgent == null) { if (systemProperties) { userAgent = Runtime.GetProperty("http.agent"); } if (userAgent == null) { userAgent = DefaultUserAgent; } } HttpProcessorBuilder b = HttpProcessorBuilder.Create(); if (requestFirst != null) { foreach (IHttpRequestInterceptor i in requestFirst) { b.AddFirst(i); } } if (responseFirst != null) { foreach (HttpResponseInterceptor i in responseFirst) { b.AddFirst(i); } } b.AddAll(new RequestDefaultHeaders(defaultHeaders), new RequestContent(), new RequestTargetHost (), new RequestClientConnControl(), new RequestUserAgent(userAgent), new RequestExpectContinue ()); if (!cookieManagementDisabled) { b.Add(new RequestAddCookies()); } if (!contentCompressionDisabled) { b.Add(new RequestAcceptEncoding()); } if (!authCachingDisabled) { b.Add(new RequestAuthCache()); } if (!cookieManagementDisabled) { b.Add(new ResponseProcessCookies()); } if (!contentCompressionDisabled) { b.Add(new ResponseContentEncoding()); } if (requestLast != null) { foreach (IHttpRequestInterceptor i in requestLast) { b.AddLast(i); } } if (responseLast != null) { foreach (HttpResponseInterceptor i in responseLast) { b.AddLast(i); } } httpprocessor = b.Build(); } execChain = new ProtocolExec(execChain, httpprocessor); execChain = DecorateProtocolExec(execChain); // Add request retry executor, if not disabled if (!automaticRetriesDisabled) { HttpRequestRetryHandler retryHandler = this.retryHandler; if (retryHandler == null) { retryHandler = DefaultHttpRequestRetryHandler.Instance; } execChain = new RetryExec(execChain, retryHandler); } HttpRoutePlanner routePlanner = this.routePlanner; if (routePlanner == null) { SchemePortResolver schemePortResolver = this.schemePortResolver; if (schemePortResolver == null) { schemePortResolver = DefaultSchemePortResolver.Instance; } if (proxy != null) { routePlanner = new DefaultProxyRoutePlanner(proxy, schemePortResolver); } else { if (systemProperties) { routePlanner = new SystemDefaultRoutePlanner(schemePortResolver, ProxySelector.GetDefault ()); } else { routePlanner = new DefaultRoutePlanner(schemePortResolver); } } } // Add redirect executor, if not disabled if (!redirectHandlingDisabled) { RedirectStrategy redirectStrategy = this.redirectStrategy; if (redirectStrategy == null) { redirectStrategy = DefaultRedirectStrategy.Instance; } execChain = new RedirectExec(execChain, routePlanner, redirectStrategy); } // Optionally, add service unavailable retry executor ServiceUnavailableRetryStrategy serviceUnavailStrategy = this.serviceUnavailStrategy; if (serviceUnavailStrategy != null) { execChain = new ServiceUnavailableRetryExec(execChain, serviceUnavailStrategy); } // Optionally, add connection back-off executor BackoffManager backoffManager = this.backoffManager; ConnectionBackoffStrategy connectionBackoffStrategy = this.connectionBackoffStrategy; if (backoffManager != null && connectionBackoffStrategy != null) { execChain = new BackoffStrategyExec(execChain, connectionBackoffStrategy, backoffManager ); } Lookup <AuthSchemeProvider> authSchemeRegistry = this.authSchemeRegistry; if (authSchemeRegistry == null) { authSchemeRegistry = RegistryBuilder.Create <AuthSchemeProvider>().Register(AuthSchemes .Basic, new BasicSchemeFactory()).Register(AuthSchemes.Digest, new DigestSchemeFactory ()).Register(AuthSchemes.Ntlm, new NTLMSchemeFactory()).Register(AuthSchemes.Spnego , new SPNegoSchemeFactory()).Register(AuthSchemes.Kerberos, new KerberosSchemeFactory ()).Build(); } Lookup <CookieSpecProvider> cookieSpecRegistry = this.cookieSpecRegistry; if (cookieSpecRegistry == null) { cookieSpecRegistry = RegistryBuilder.Create <CookieSpecProvider>().Register(CookieSpecs .BestMatch, new BestMatchSpecFactory()).Register(CookieSpecs.Standard, new RFC2965SpecFactory ()).Register(CookieSpecs.BrowserCompatibility, new BrowserCompatSpecFactory()).Register (CookieSpecs.Netscape, new NetscapeDraftSpecFactory()).Register(CookieSpecs.IgnoreCookies , new IgnoreSpecFactory()).Register("rfc2109", new RFC2109SpecFactory()).Register ("rfc2965", new RFC2965SpecFactory()).Build(); } CookieStore defaultCookieStore = this.cookieStore; if (defaultCookieStore == null) { defaultCookieStore = new BasicCookieStore(); } CredentialsProvider defaultCredentialsProvider = this.credentialsProvider; if (defaultCredentialsProvider == null) { if (systemProperties) { defaultCredentialsProvider = new SystemDefaultCredentialsProvider(); } else { defaultCredentialsProvider = new BasicCredentialsProvider(); } } return(new InternalHttpClient(execChain, connManager, routePlanner, cookieSpecRegistry , authSchemeRegistry, defaultCookieStore, defaultCredentialsProvider, defaultRequestConfig != null ? defaultRequestConfig : RequestConfig.Default, closeables != null ? new AList <IDisposable>(closeables) : null)); }
/// <summary>Create a new S3 client for the supplied user information.</summary> /// <remarks> /// Create a new S3 client for the supplied user information. /// <p> /// The connection properties are a subset of those supported by the popular /// <a href="http://jets3t.s3.amazonaws.com/index.html">jets3t</a> library. /// For example: /// <pre> /// # AWS Access and Secret Keys (required) /// accesskey: <YourAWSAccessKey> /// secretkey: <YourAWSSecretKey> /// # Access Control List setting to apply to uploads, must be one of: /// # PRIVATE, PUBLIC_READ (defaults to PRIVATE). /// acl: PRIVATE /// # Number of times to retry after internal error from S3. /// httpclient.retry-max: 3 /// # End-to-end encryption (hides content from S3 owners) /// password: <encryption pass-phrase> /// crypto.algorithm: PBEWithMD5AndDES /// </pre> /// </remarks> /// <param name="props">connection properties.</param> public AmazonS3(Sharpen.Properties props) { publicKey = props.GetProperty("accesskey"); if (publicKey == null) { throw new ArgumentException(JGitText.Get().missingAccesskey); } string secret = props.GetProperty("secretkey"); if (secret == null) { throw new ArgumentException(JGitText.Get().missingSecretkey); } privateKey = new SecretKeySpec(Constants.EncodeASCII(secret), HMAC); string pacl = props.GetProperty("acl", "PRIVATE"); if (StringUtils.EqualsIgnoreCase("PRIVATE", pacl)) { acl = "private"; } else { if (StringUtils.EqualsIgnoreCase("PUBLIC", pacl)) { acl = "public-read"; } else { if (StringUtils.EqualsIgnoreCase("PUBLIC-READ", pacl)) { acl = "public-read"; } else { if (StringUtils.EqualsIgnoreCase("PUBLIC_READ", pacl)) { acl = "public-read"; } else { throw new ArgumentException("Invalid acl: " + pacl); } } } } try { string cPas = props.GetProperty("password"); if (cPas != null) { string cAlg = props.GetProperty("crypto.algorithm"); if (cAlg == null) { cAlg = "PBEWithMD5AndDES"; } encryption = new WalkEncryption.ObjectEncryptionV2(cAlg, cPas); } else { encryption = WalkEncryption.NONE; } } catch (InvalidKeySpecException e) { throw new ArgumentException(JGitText.Get().invalidEncryption, e); } catch (NoSuchAlgorithmException e) { throw new ArgumentException(JGitText.Get().invalidEncryption, e); } maxAttempts = System.Convert.ToInt32(props.GetProperty("httpclient.retry-max", "3" )); proxySelector = ProxySelector.GetDefault(); }