public void proxy(final Proxy proxy, final boolean secure) { proxyInfo = new ProxyInfo(proxy, secure); }
public int getPort() { return getSocketAddress().getPort(); }
private <T extends HttpRequestBase> Object exec(final ChainedHttpConfig requestConfig, final Function<URI, T> constructor) { try { final ChainedHttpConfig.ChainedRequest cr = requestConfig.getChainedRequest(); final URI theUri = cr.getUri().toURI(); final T request = constructor.apply(theUri); if ((request instanceof HttpEntityEnclosingRequest) && cr.actualBody() != null) { final HttpEntity entity = entity(requestConfig); ((HttpEntityEnclosingRequest) request).setEntity(entity); request.setHeader(entity.getContentType()); } addHeaders(cr, request); if (proxyInfo != null && proxyInfo.getProxy().type() == Proxy.Type.HTTP) { HttpHost proxy = new HttpHost(proxyInfo.getAddress(), proxyInfo.getPort(), proxyInfo.isSecure() ? "https" : "http"); request.setConfig(RequestConfig.custom().setProxy(proxy).build()); } return client.execute(request, new Handler(requestConfig), context(requestConfig)); } catch (Exception e) { return handleException(requestConfig.getChainedResponse(), e); } }
private boolean isProxied() { return proxyInfo != null && proxyInfo.getProxy().type() != Proxy.Type.DIRECT; }
private <T extends HttpRequestBase> Object exec(final ChainedHttpConfig requestConfig, final Function<URI, T> constructor) { try { final ChainedHttpConfig.ChainedRequest cr = requestConfig.getChainedRequest(); final URI theUri = cr.getUri().toURI(); final T request = constructor.apply(theUri); if ((request instanceof HttpEntityEnclosingRequest) && cr.actualBody() != null) { final HttpEntity entity = entity(requestConfig); ((HttpEntityEnclosingRequest) request).setEntity(entity); request.setHeader(entity.getContentType()); } addHeaders(cr, request); if (proxyInfo != null && proxyInfo.getProxy().type() == Proxy.Type.HTTP) { HttpHost proxy = new HttpHost(proxyInfo.getAddress(), proxyInfo.getPort(), proxyInfo.isSecure() ? "https" : "http"); request.setConfig(RequestConfig.custom().setProxy(proxy).build()); } return client.execute(request, new Handler(requestConfig), context(requestConfig)); } catch (Exception e) { return handleException(requestConfig.getChainedResponse(), e); } }
private boolean isProxied() { return proxyInfo != null && proxyInfo.getProxy().type() != Proxy.Type.DIRECT; }
private boolean usesProxy(final ProxyInfo pinfo) { return pinfo != null && pinfo.getProxy().type() != Proxy.Type.DIRECT; }
public InetAddress getAddress() { return getSocketAddress().getAddress(); }
public void proxy(String host, int port, Proxy.Type type, boolean secure) throws UnknownHostException { proxyInfo = new ProxyInfo(host, port, type, secure); }
public Action(final Consumer<Object> clientCustomizer, final ChainedHttpConfig requestConfig, final String verb) throws IOException, URISyntaxException { this.requestConfig = requestConfig; final ChainedHttpConfig.ChainedRequest cr = requestConfig.getChainedRequest(); theUri = cr.getUri().toURI(); final URL url = theUri.toURL(); connection = (HttpURLConnection) (isProxied() ? url.openConnection(proxyInfo.getProxy()) : url.openConnection()); connection.setRequestMethod(verb); if (cr.actualBody() != null) { connection.setDoOutput(true); } if (clientCustomizer != null) { clientCustomizer.accept(connection); } }
public int getPort() { return getSocketAddress().getPort(); }
public void proxy(String host, int port, Proxy.Type type, boolean secure) throws UnknownHostException { proxyInfo = new ProxyInfo(host, port, type, secure); }
public Action(final Consumer<Object> clientCustomizer, final ChainedHttpConfig requestConfig, final String verb) throws IOException, URISyntaxException { this.requestConfig = requestConfig; final ChainedHttpConfig.ChainedRequest cr = requestConfig.getChainedRequest(); theUri = cr.getUri().toURI(); final URL url = theUri.toURL(); connection = (HttpURLConnection) (isProxied() ? url.openConnection(proxyInfo.getProxy()) : url.openConnection()); connection.setRequestMethod(verb); if (cr.actualBody() != null) { connection.setDoOutput(true); } if (clientCustomizer != null) { clientCustomizer.accept(connection); } }
public InetAddress getAddress() { return getSocketAddress().getAddress(); }
public void proxy(final Proxy proxy, final boolean secure) { proxyInfo = new ProxyInfo(proxy, secure); }
private Registry<ConnectionSocketFactory> registry(final HttpObjectConfig config) { final ProxyInfo proxyInfo = config.getExecution().getProxyInfo(); final boolean isSocksProxied = (proxyInfo != null && proxyInfo.getProxy().type() == Proxy.Type.SOCKS); if (isSocksProxied) { return RegistryBuilder.<ConnectionSocketFactory>create() .register("http", new SocksHttp(proxyInfo.getProxy())) .register("https", new SocksHttps(proxyInfo.getProxy(), sslContext(config), config.getExecution().getHostnameVerifier())) .build(); } else { return RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", new SSLConnectionSocketFactory(sslContext(config), config.getExecution().getHostnameVerifier())) .build(); } }
private Registry<ConnectionSocketFactory> registry(final HttpObjectConfig config) { final ProxyInfo proxyInfo = config.getExecution().getProxyInfo(); final boolean isSocksProxied = (proxyInfo != null && proxyInfo.getProxy().type() == Proxy.Type.SOCKS); if (isSocksProxied) { return RegistryBuilder.<ConnectionSocketFactory>create() .register("http", new SocksHttp(proxyInfo.getProxy())) .register("https", new SocksHttps(proxyInfo.getProxy(), sslContext(config), config.getExecution().getHostnameVerifier())) .build(); } else { return RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", new SSLConnectionSocketFactory(sslContext(config), config.getExecution().getHostnameVerifier())) .build(); } }
protected OkHttpBuilder(final HttpObjectConfig config) { super(config); this.config = new HttpConfigs.ThreadSafeHttpConfig(config.getChainedConfig()); this.clientConfig = config.getClient(); this.executor = config.getExecution().getExecutor(); final OkHttpClient.Builder builder = new OkHttpClient.Builder(); final SSLContext sslContext = config.getExecution().getSslContext(); if (sslContext != null) { builder.sslSocketFactory(sslContext.getSocketFactory()/*, (X509TrustManager) TRUST_MANAGERS[0]*/); builder.hostnameVerifier(config.getExecution().getHostnameVerifier()); } // DIGEST support - defining this here only allows DIGEST config on the HttpBuilder configuration, not for individual methods. final HttpConfig.Auth auth = config.getRequest().getAuth(); if (auth != null && auth.getAuthType() == DIGEST) { Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>(); builder.addInterceptor(new AuthenticationCacheInterceptor(authCache)); builder.authenticator(new CachingAuthenticatorDecorator( new DigestAuthenticator(new com.burgstaller.okhttp.digest.Credentials(auth.getUser(), auth.getPassword())), authCache) ); } final Consumer<Object> clientCustomizer = clientConfig.getClientCustomizer(); if (clientCustomizer != null) { clientCustomizer.accept(builder); } final ProxyInfo pinfo = config.getExecution().getProxyInfo(); if (usesProxy(pinfo)) { builder.proxy(pinfo.getProxy()); } this.client = builder.build(); }