本文整理了Java中org.asynchttpclient.uri.Uri.getHost()
方法的一些代码示例,展示了Uri.getHost()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Uri.getHost()
方法的具体详情如下:
包路径:org.asynchttpclient.uri.Uri
类名称:Uri
方法名:getHost
暂无
代码示例来源:origin: AsyncHttpClient/async-http-client
private String requestDomain(Uri requestUri) {
return requestUri.getHost().toLowerCase();
}
代码示例来源:origin: AsyncHttpClient/async-http-client
public boolean isSameBase(Uri other) {
return scheme.equals(other.getScheme())
&& host.equals(other.getHost())
&& getExplicitPort() == other.getExplicitPort();
}
代码示例来源:origin: AsyncHttpClient/async-http-client
public static String hostHeader(Uri uri) {
String host = uri.getHost();
int port = uri.getPort();
return port == -1 || port == uri.getSchemeDefaultPort() ? host : host + ":" + port;
}
代码示例来源:origin: AsyncHttpClient/async-http-client
public static String originHeader(Uri uri) {
StringBuilder sb = StringBuilderPool.DEFAULT.stringBuilder();
sb.append(uri.isSecured() ? "https://" : "http://").append(uri.getHost());
if (uri.getExplicitPort() != uri.getSchemeDefaultPort()) {
sb.append(':').append(uri.getPort());
}
return sb.toString();
}
代码示例来源:origin: AsyncHttpClient/async-http-client
public SslHandler addSslHandler(ChannelPipeline pipeline, Uri uri, String virtualHost, boolean hasSocksProxyHandler) {
String peerHost;
int peerPort;
if (virtualHost != null) {
int i = virtualHost.indexOf(':');
if (i == -1) {
peerHost = virtualHost;
peerPort = uri.getSchemeDefaultPort();
} else {
peerHost = virtualHost.substring(0, i);
peerPort = Integer.valueOf(virtualHost.substring(i + 1));
}
} else {
peerHost = uri.getHost();
peerPort = uri.getExplicitPort();
}
SslHandler sslHandler = createSslHandler(peerHost, peerPort);
if (hasSocksProxyHandler) {
pipeline.addAfter(SOCKS_HANDLER, SSL_HANDLER, sslHandler);
} else {
pipeline.addFirst(SSL_HANDLER, sslHandler);
}
return sslHandler;
}
代码示例来源:origin: AsyncHttpClient/async-http-client
private static void assertUriEquals(Uri uri, URI javaUri) {
assertEquals(uri.getScheme(), javaUri.getScheme());
assertEquals(uri.getUserInfo(), javaUri.getUserInfo());
assertEquals(uri.getHost(), javaUri.getHost());
assertEquals(uri.getPort(), javaUri.getPort());
assertEquals(uri.getPath(), javaUri.getPath());
assertEquals(uri.getQuery(), javaUri.getQuery());
}
代码示例来源:origin: AsyncHttpClient/async-http-client
private boolean overrideWithContext(Uri context) {
boolean isRelative = false;
// use context only if schemes match
if (context != null && (scheme == null || scheme.equalsIgnoreCase(context.getScheme()))) {
// see RFC2396 5.2.3
String contextPath = context.getPath();
if (isNonEmpty(contextPath) && contextPath.charAt(0) == '/') {
scheme = null;
}
if (scheme == null) {
scheme = context.getScheme();
userInfo = context.getUserInfo();
host = context.getHost();
port = context.getPort();
path = contextPath;
isRelative = true;
}
}
return isRelative;
}
代码示例来源:origin: AsyncHttpClient/async-http-client
/**
* @param config the global config
* @param request the request
* @return the proxy server to be used for this request (can be null)
*/
public static ProxyServer getProxyServer(AsyncHttpClientConfig config, Request request) {
ProxyServer proxyServer = request.getProxyServer();
if (proxyServer == null) {
ProxyServerSelector selector = config.getProxyServerSelector();
if (selector != null) {
proxyServer = selector.select(request.getUri());
}
}
return proxyServer != null && !proxyServer.isIgnoredForHost(request.getUri().getHost()) ? proxyServer : null;
}
代码示例来源:origin: AsyncHttpClient/async-http-client
public Future<Channel> updatePipelineForHttpTunneling(ChannelPipeline pipeline, Uri requestUri) {
Future<Channel> whenHanshaked = null;
if (pipeline.get(HTTP_CLIENT_CODEC) != null)
pipeline.remove(HTTP_CLIENT_CODEC);
if (requestUri.isSecured()) {
if (!isSslHandlerConfigured(pipeline)) {
SslHandler sslHandler = createSslHandler(requestUri.getHost(), requestUri.getExplicitPort());
whenHanshaked = sslHandler.handshakeFuture();
pipeline.addBefore(INFLATER_HANDLER, SSL_HANDLER, sslHandler);
}
pipeline.addAfter(SSL_HANDLER, HTTP_CLIENT_CODEC, newHttpClientCodec());
} else {
pipeline.addBefore(AHC_HTTP_HANDLER, HTTP_CLIENT_CODEC, newHttpClientCodec());
}
if (requestUri.isWebSocket()) {
pipeline.addAfter(AHC_HTTP_HANDLER, AHC_WS_HANDLER, wsHandler);
pipeline.remove(AHC_HTTP_HANDLER);
}
return whenHanshaked;
}
代码示例来源:origin: AsyncHttpClient/async-http-client
private <T> Future<List<InetSocketAddress>> resolveAddresses(Request request,
ProxyServer proxy,
NettyResponseFuture<T> future,
AsyncHandler<T> asyncHandler) {
Uri uri = request.getUri();
final Promise<List<InetSocketAddress>> promise = ImmediateEventExecutor.INSTANCE.newPromise();
if (proxy != null && !proxy.isIgnoredForHost(uri.getHost()) && proxy.getProxyType().isHttp()) {
int port = uri.isSecured() ? proxy.getSecuredPort() : proxy.getPort();
InetSocketAddress unresolvedRemoteAddress = InetSocketAddress.createUnresolved(proxy.getHost(), port);
scheduleRequestTimeout(future, unresolvedRemoteAddress);
return RequestHostnameResolver.INSTANCE.resolve(request.getNameResolver(), unresolvedRemoteAddress, asyncHandler);
} else {
int port = uri.getExplicitPort();
InetSocketAddress unresolvedRemoteAddress = InetSocketAddress.createUnresolved(uri.getHost(), port);
scheduleRequestTimeout(future, unresolvedRemoteAddress);
if (request.getAddress() != null) {
// bypass resolution
InetSocketAddress inetSocketAddress = new InetSocketAddress(request.getAddress(), port);
return promise.setSuccess(singletonList(inetSocketAddress));
} else {
return RequestHostnameResolver.INSTANCE.resolve(request.getNameResolver(), unresolvedRemoteAddress, asyncHandler);
}
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
public Uri encode(Uri uri, List<Param> queryParams) {
String newPath = encodePath(uri.getPath());
String newQuery = encodeQuery(uri.getQuery(), queryParams);
return new Uri(uri.getScheme(),
uri.getUserInfo(),
uri.getHost(),
uri.getPort(),
newPath,
newQuery,
uri.getFragment());
}
代码示例来源:origin: AsyncHttpClient/async-http-client
private void kerberosChallenge(Realm realm,
Request request,
HttpHeaders headers) throws SpnegoEngineException {
Uri uri = request.getUri();
String host = withDefault(request.getVirtualHost(), uri.getHost());
String challengeHeader = SpnegoEngine.instance(realm.getPrincipal(),
realm.getPassword(),
realm.getServicePrincipalName(),
realm.getRealmName(),
realm.isUseCanonicalHostname(),
realm.getCustomLoginConfig(),
realm.getLoginContextName()).generateToken(host);
headers.set(AUTHORIZATION, NEGOTIATE + " " + challengeHeader);
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test
public void testNonProxyHost() {
// // should avoid, it's in non-proxy hosts
Request req = get("http://somewhere.com/foo").build();
ProxyServer proxyServer = proxyServer("localhost", 1234).setNonProxyHost("somewhere.com").build();
assertTrue(proxyServer.isIgnoredForHost(req.getUri().getHost()));
//
// // should avoid, it's in non-proxy hosts (with "*")
req = get("http://sub.somewhere.com/foo").build();
proxyServer = proxyServer("localhost", 1234).setNonProxyHost("*.somewhere.com").build();
assertTrue(proxyServer.isIgnoredForHost(req.getUri().getHost()));
// should use it
req = get("http://sub.somewhere.com/foo").build();
proxyServer = proxyServer("localhost", 1234).setNonProxyHost("*.somewhere.com").build();
assertTrue(proxyServer.isIgnoredForHost(req.getUri().getHost()));
}
代码示例来源:origin: AsyncHttpClient/async-http-client
host = request.getVirtualHost();
else
host = request.getUri().getHost();
代码示例来源:origin: com.tomitribe.tribestream/tribestream-container
private static APIConnectionExecutor getExecutor(final Uri requestUri) {
final APIConnectionExecutor executor;
if (requestUri.getHost() != null && API_URL_SCHEME.equals(requestUri.getScheme())) {
executor = API_CONNECTIONS_EXECUTORS.getOrDefault(IdGenerator.from(requestUri.getHost()),
DEFAULT_API_CONNECTION_EXECUTOR);
} else {
executor = DEFAULT_API_CONNECTION_EXECUTOR;
}
return executor;
}
}
代码示例来源:origin: com.tomitribe.tribestream/tribestream-container
@Override
public Request build() {
retries++;
// On request retry, the host may change, so we need to replace the Host headers with the new host.
setHeader(HOST, uri.getHost());
return super.build();
}
代码示例来源:origin: org.asynchttpclient/async-http-client-api
/**
* @see #ignoreProxy(ProxyServer, String)
*/
public static boolean avoidProxy(final ProxyServer proxyServer, final Request request) {
return ignoreProxy(proxyServer, request.getUri().getHost());
}
代码示例来源:origin: org.asynchttpclient/async-http-client-api
public static String hostHeader(Request request, Uri uri) {
String virtualHost = request.getVirtualHost();
if (virtualHost != null)
return virtualHost;
else {
String host = uri.getHost();
int port = uri.getPort();
return port == -1 || port == uri.getSchemeDefaultPort() ? host : host + ":" + port;
}
}
}
代码示例来源:origin: com.tomitribe.tribestream/tribestream-container
public APIConnectionRequestBuilder appendPath(final String path) {
this.uri = new Uri(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery());
return this;
}
代码示例来源:origin: org.asynchttpclient/async-http-client-api
public Uri encode(Uri uri, List<Param> queryParams) {
String newPath = encodePath(uri.getPath());
String newQuery = encodeQuery(uri.getQuery(), queryParams);
return new Uri(uri.getScheme(),//
uri.getUserInfo(),//
uri.getHost(),//
uri.getPort(),//
newPath,//
newQuery);
}
内容来源于网络,如有侵权,请联系作者删除!