/** * Defines auth scope for a specific host of origin. * * @param origin host of origin * @param realm authentication realm. May be {@code null} if applies * to any realm on the host. * @param schemeName authentication authScheme. May be {@code null} if applies * to any authScheme supported by the host. * * @since 4.2 */ public AuthScope( final HttpHost origin, final String realm, final String schemeName) { Args.notNull(origin, "Host"); this.protocol = origin.getSchemeName().toLowerCase(Locale.ROOT); this.host = origin.getHostName().toLowerCase(Locale.ROOT); this.port = origin.getPort() >= 0 ? origin.getPort() : -1; this.realm = realm; this.authScheme = schemeName != null ? schemeName.toUpperCase(Locale.ROOT): null; }
private HttpRoute(final HttpHost targetHost, final InetAddress local, final List<HttpHost> proxies, final boolean secure, final TunnelType tunnelled, final LayerType layered) { Args.notNull(targetHost, "Target host"); Args.notNegative(targetHost.getPort(), "Target port"); this.targetHost = targetHost; this.localAddress = local; if (proxies != null && !proxies.isEmpty()) { this.proxyChain = new ArrayList<>(proxies); } else { this.proxyChain = null; } if (tunnelled == TunnelType.TUNNELLED) { Args.check(this.proxyChain != null, "Proxy required if tunnelled"); } this.secure = secure; this.tunnelled = tunnelled != null ? tunnelled : TunnelType.PLAIN; this.layered = layered != null ? layered : LayerType.PLAIN; }
private InetSocketAddress toSocketAddress(final HttpHost host) { int port = host.getPort(); if (port < 0) { final String scheme = host.getSchemeName(); if (URIScheme.HTTP.same(scheme)) { port = 80; } else if (URIScheme.HTTPS.same(scheme)) { port = 443; } } final String hostName = host.getHostName(); return new InetSocketAddress(hostName, port); }
private InetSocketAddress toSocketAddress(final HttpHost host) { int port = host.getPort(); if (port < 0) { final String scheme = host.getSchemeName(); if (URIScheme.HTTP.same(scheme)) { port = 80; } else if (URIScheme.HTTPS.same(scheme)) { port = 443; } } final String hostName = host.getHostName(); return new InetSocketAddress(hostName, port); }
@Override public InetSocketAddress resolve(final HttpHost host) { if (host == null) { return null; } int port = host.getPort(); if (port < 0) { final String scheme = host.getSchemeName(); if (URIScheme.HTTP.same(scheme)) { port = 80; } else if (URIScheme.HTTPS.same(scheme)) { port = 443; } } return new InetSocketAddress(host.getHostName(), port); }
@Override public InetSocketAddress resolve(final HttpHost host) { if (host == null) { return null; } int port = host.getPort(); if (port < 0) { final String scheme = host.getSchemeName(); if (URIScheme.HTTP.same(scheme)) { port = 80; } else if (URIScheme.HTTPS.same(scheme)) { port = 443; } } return new InetSocketAddress(host.getHostName(), port); }
public static HttpHost normalize(final HttpHost host, final SchemePortResolver schemePortResolver) { if (host == null) { return null; } if (host.getPort() < 0) { final int port = (schemePortResolver != null ? schemePortResolver: DefaultSchemePortResolver.INSTANCE).resolve(host); if (port > 0) { return new HttpHost(host.getSchemeName(), host.getHostName(), port); } } return host; }
@Override public int resolve(final HttpHost host) { Args.notNull(host, "HTTP host"); final int port = host.getPort(); if (port > 0) { return port; } final String name = host.getSchemeName(); if (URIScheme.HTTP.same(name)) { return 80; } else if (URIScheme.HTTPS.same(name)) { return 443; } else { return -1; } }
/** * Sets the scheme, host name, and port. * * @param httpHost the scheme, host name, and port. * @return this. */ public URIBuilder setHttpHost(final HttpHost httpHost ) { setScheme(httpHost.getSchemeName()); setHost(httpHost.getHostName()); setPort(httpHost.getPort()); return this; }
/** * Sets the scheme, host name, and port. * * @param httpHost the scheme, host name, and port. * @return this. */ public URIBuilder setHttpHost(final HttpHost httpHost ) { setScheme(httpHost.getSchemeName()); setHost(httpHost.getHostName()); setPort(httpHost.getPort()); return this; }
public static HttpHost resolveAuthTarget(final HttpRequest request, final HttpRoute route) { Args.notNull(request, "Request"); Args.notNull(route, "Route"); final URIAuthority authority = request.getAuthority(); final String scheme = request.getScheme(); final HttpHost target = authority != null ? new HttpHost(scheme, authority) : route.getTargetHost(); if (target.getPort() < 0) { return new HttpHost( target.getSchemeName(), target.getHostName(), route.getTargetHost().getPort()); } return target; }
/** * Convenience factory method for {@link URI} instances. * * @since 5.0 */ public static URI create(final HttpHost host, final String path) throws URISyntaxException { final URIBuilder builder = new URIBuilder(path); if (host != null) { builder.setHost(host.getHostName()).setPort(host.getPort()).setScheme(host.getSchemeName()); } return builder.build(); }
uribuilder.setScheme(target.getSchemeName()); uribuilder.setHost(target.getHostName()); uribuilder.setPort(target.getPort());
connectionInitiator, remoteEndpoint, remoteAddress != null ? new InetSocketAddress(remoteAddress, remoteEndpoint.getPort()) : null, localAddress, connectTimeout,
@Override public final HttpRoute determineRoute(final HttpHost host, final HttpContext context) throws HttpException { if (host == null) { throw new ProtocolException("Target host is not specified"); } final HttpClientContext clientContext = HttpClientContext.adapt(context); final RequestConfig config = clientContext.getRequestConfig(); HttpHost proxy = config.getProxy(); if (proxy == null) { proxy = determineProxy(host, context); } final HttpHost target = RoutingSupport.normalize(host, schemePortResolver); if (target.getPort() < 0) { throw new ProtocolException("Unroutable protocol scheme: " + target); } final boolean secure = target.getSchemeName().equalsIgnoreCase("https"); if (proxy == null) { return new HttpRoute(target, determineLocalAddress(target, context), secure); } else { return new HttpRoute(target, determineLocalAddress(proxy, context), proxy, secure); } }
uribuilder.setScheme(target.getSchemeName()); uribuilder.setHost(target.getHostName()); uribuilder.setPort(target.getPort()); } else { uribuilder.setScheme(null);
final HttpHost host1 = new HttpHost("somehost"); Assert.assertEquals("somehost", host1.getHostName()); Assert.assertEquals(-1, host1.getPort()); Assert.assertEquals("http", host1.getSchemeName()); final HttpHost host2 = new HttpHost("somehost", 8080); Assert.assertEquals("somehost", host2.getHostName()); Assert.assertEquals(8080, host2.getPort()); Assert.assertEquals("http", host2.getSchemeName()); final HttpHost host3 = new HttpHost("somehost", -1); Assert.assertEquals("somehost", host3.getHostName()); Assert.assertEquals(-1, host3.getPort()); Assert.assertEquals("http", host3.getSchemeName()); final HttpHost host4 = new HttpHost("https", "somehost", 443); Assert.assertEquals("somehost", host4.getHostName()); Assert.assertEquals(443, host4.getPort()); Assert.assertEquals("https", host4.getSchemeName()); final HttpHost host5 = new HttpHost("https", "somehost"); Assert.assertEquals("somehost", host5.getHostName()); Assert.assertEquals(-1, host5.getPort()); Assert.assertEquals("https", host5.getSchemeName()); try {