buf.append(target.getSchemeName()).append("://"); buf.append(target.getHostName()); if (target.getPort() >= 0) {
@Override public boolean upgrade( final TransportSecurityLayer tlsSession, final HttpHost host, final SocketAddress localAddress, final SocketAddress remoteAddress, final Object attachment) { final String scheme = host != null ? host.getSchemeName() : null; if (URIScheme.HTTPS.same(scheme)) { tlsSession.startTls(sslContext, host, sslBufferMode, initializer, verifier); return true; } return false; }
/** * Creates request message with the given method, host and request path. * * @param method request method. * @param host request host. * @param path request path. * * @since 5.0 */ public BasicHttpRequest(final String method, final HttpHost host, final String path) { super(); this.method = Args.notNull(method, "Method name"); this.scheme = host != null ? host.getSchemeName() : null; this.authority = host != null ? new URIAuthority(host) : null; this.path = path; }
@Override public boolean upgrade( final TransportSecurityLayer tlsSession, final HttpHost host, final SocketAddress localAddress, final SocketAddress remoteAddress, final Object attachment, final Timeout handshakeTimeout) { final String scheme = host != null ? host.getSchemeName() : null; if (URIScheme.HTTPS.same(scheme)) { tlsSession.startTls(sslContext, host, sslBufferMode, initializer, verifier, handshakeTimeout); return true; } return false; }
/** * Creates request message with the given method, host and request path. * * @param method request method. * @param host request host. * @param path request path. * * @since 5.0 */ public BasicHttpRequest(final String method, final HttpHost host, final String path) { super(); this.method = Args.notNull(method, "Method name"); this.scheme = host != null ? host.getSchemeName() : null; this.authority = host != null ? new URIAuthority(host) : null; this.path = path; }
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); }
public ClassicHttpResponse execute( final HttpHost targetHost, final ClassicHttpRequest request, final HttpContext context) throws HttpException, IOException { final HttpRequester requester = this.requesterRef.get(); if (requester == null) { throw new IllegalStateException("Requester has not been started"); } if (request.getAuthority() == null) { request.setAuthority(new URIAuthority(targetHost)); } request.setScheme(targetHost.getSchemeName()); return requester.execute(targetHost, request, socketConfig.getSoTimeout(), context); }
public ClassicHttpResponse execute( final HttpHost targetHost, final ClassicHttpRequest request, final HttpContext context) throws HttpException, IOException { final HttpRequester requester = this.requesterRef.get(); if (requester == null) { throw new IllegalStateException("Requester has not been started"); } if (request.getAuthority() == null) { request.setAuthority(new URIAuthority(targetHost)); } request.setScheme(targetHost.getSchemeName()); return requester.execute(targetHost, request, socketConfig.getSoTimeout(), context); }
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 void upgrade(final ManagedAsyncClientConnection connection, final HttpHost host, final Object attachment) { final TlsStrategy tlsStrategy = tlsStrategyLookup != null ? tlsStrategyLookup.lookup(host.getSchemeName()) : null; if (tlsStrategy != null) { tlsStrategy.upgrade( connection, host, connection.getLocalAddress(), connection.getRemoteAddress(), attachment); } } }
@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; }
/** * 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(); }
@Override public void completed(final IOSession ioSession) { if (tlsStrategy != null && URIScheme.HTTPS.same(namedEndpoint.getSchemeName()) && ioSession instanceof TransportSecurityLayer) { tlsStrategy.upgrade( (TransportSecurityLayer) ioSession, namedEndpoint, ioSession.getLocalAddress(), ioSession.getRemoteAddress(), null, connectTimeout); ioSession.setSocketTimeout(connectTimeout); } callback.completed(ioSession); }
@Override public IOEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) { if (tlsStrategy != null && ioSession.getInitialEndpoint() instanceof HttpHost) { final HttpHost host = (HttpHost) ioSession.getInitialEndpoint(); if (URIScheme.HTTPS.same(host.getSchemeName())) { tlsStrategy.upgrade( ioSession, host, ioSession.getLocalAddress(), ioSession.getRemoteAddress(), attachment); } } return new ClientHttp1IOEventHandler(streamDuplexerFactory.create(ioSession)); }
@Override public IOEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) { if (tlsStrategy != null && ioSession.getInitialEndpoint() instanceof HttpHost) { final HttpHost host = (HttpHost) ioSession.getInitialEndpoint(); if (URIScheme.HTTPS.same(host.getSchemeName())) { tlsStrategy.upgrade( ioSession, host, ioSession.getLocalAddress(), ioSession.getRemoteAddress(), attachment, handshakeTimeout); } } return new ClientHttp1IOEventHandler(streamDuplexerFactory.create(ioSession)); }
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; }