buf.append(target.getHostName()); if (target.getPort() >= 0) { buf.append(":").append(target.getPort());
final RouteInfo route = clientContext.getHttpRoute(); if (route != null) { spn = "HTTP/" + route.getProxyHost().getHostName(); } else { final RouteInfo route = clientContext.getHttpRoute(); if (route != null) { spn = "HTTP/" + route.getTargetHost().getHostName(); } else {
@Override public TlsDetails verify(final NamedEndpoint endpoint, final SSLEngine sslEngine) throws SSLException { verifySession(host.getHostName(), sslEngine.getSession()); return createTlsDetails(sslEngine); }
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); }
/** * 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; }
@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); }
this.log.debug("Starting handshake"); sslsock.startHandshake(); verifyHostname(sslsock, host.getHostName()); return sock; return createLayeredSocket(sock, host.getHostName(), remoteAddress.getPort(), context);
final RouteInfo route = clientContext.getHttpRoute(); if (route != null) { spn = "HTTP/" + route.getProxyHost().getHostName(); } else { final RouteInfo route = clientContext.getHttpRoute(); if (route != null) { spn = "HTTP/" + route.getTargetHost().getHostName(); } else {
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; }
private Socket createSocket(final HttpHost targetHost) throws IOException { final Socket sock = new Socket(); sock.setSoTimeout(socketConfig.getSoTimeout().toMillisIntBound()); sock.setReuseAddress(socketConfig.isSoReuseAddress()); sock.setTcpNoDelay(socketConfig.isTcpNoDelay()); sock.setKeepAlive(socketConfig.isSoKeepAlive()); if (socketConfig.getRcvBufSize() > 0) { sock.setReceiveBufferSize(socketConfig.getRcvBufSize()); } if (socketConfig.getSndBufSize() > 0) { sock.setSendBufferSize(socketConfig.getSndBufSize()); } final int linger = socketConfig.getSoLinger().toMillisIntBound(); if (linger >= 0) { sock.setSoLinger(true, linger); } final InetSocketAddress targetAddress = addressResolver.resolve(targetHost); sock.connect(targetAddress, socketConfig.getSoTimeout().toMillisIntBound()); if (URIScheme.HTTPS.same(targetHost.getSchemeName())) { return sslSocketFactory.createSocket(sock, targetHost.getHostName(), targetAddress.getPort(), true); } return sock; }
private Socket createSocket(final HttpHost targetHost) throws IOException { final Socket sock = new Socket(); sock.setSoTimeout(socketConfig.getSoTimeout().toMillisIntBound()); sock.setReuseAddress(socketConfig.isSoReuseAddress()); sock.setTcpNoDelay(socketConfig.isTcpNoDelay()); sock.setKeepAlive(socketConfig.isSoKeepAlive()); if (socketConfig.getRcvBufSize() > 0) { sock.setReceiveBufferSize(socketConfig.getRcvBufSize()); } if (socketConfig.getSndBufSize() > 0) { sock.setSendBufferSize(socketConfig.getSndBufSize()); } final int linger = socketConfig.getSoLinger().toMillisIntBound(); if (linger >= 0) { sock.setSoLinger(true, linger); } final InetSocketAddress targetAddress = addressResolver.resolve(targetHost); sock.connect(targetAddress, socketConfig.getSoTimeout().toMillisIntBound()); if (URIScheme.HTTPS.same(targetHost.getSchemeName())) { return sslSocketFactory.createSocket(sock, targetHost.getHostName(), targetAddress.getPort(), true); } return sock; }
/** * 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; }
/** * 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(); }
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; }
if (target != null) { uribuilder.setScheme(target.getSchemeName()); uribuilder.setHost(target.getHostName()); uribuilder.setPort(target.getPort()); } else {
@Override public void upgrade( final ManagedHttpClientConnection conn, final HttpHost host, final HttpContext context) throws IOException { final HttpClientContext clientContext = HttpClientContext.adapt(context); final Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(clientContext); final ConnectionSocketFactory sf = registry.lookup(host.getSchemeName()); if (sf == null) { throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported"); } if (!(sf instanceof LayeredConnectionSocketFactory)) { throw new UnsupportedSchemeException(host.getSchemeName() + " protocol does not support connection upgrade"); } final LayeredConnectionSocketFactory lsf = (LayeredConnectionSocketFactory) sf; Socket sock = conn.getSocket(); if (sock == null) { throw new ConnectionClosedException("Connection is closed"); } final int port = this.schemePortResolver.resolve(host); sock = lsf.createLayeredSocket(sock, host.getHostName(), port, context); conn.bind(sock); }
@Test public void testConstructor() { 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());