本文整理了Java中com.ning.http.client.uri.Uri.getHost()
方法的一些代码示例,展示了Uri.getHost()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Uri.getHost()
方法的具体详情如下:
包路径:com.ning.http.client.uri.Uri
类名称:Uri
方法名:getHost
暂无
代码示例来源:origin: com.ning/async-http-client
public final static boolean isSameHostAndProtocol(Uri uri1, Uri uri2) {
return uri1.getScheme().equals(uri2.getScheme()) && uri1.getHost().equals(uri2.getHost())
&& getDefaultPort(uri1) == getDefaultPort(uri2);
}
代码示例来源:origin: com.ning/async-http-client
/**
* @see #avoidProxy(ProxyServer, String)
*/
public static boolean avoidProxy(final ProxyServer proxyServer, final Request request) {
return avoidProxy(proxyServer, request.getUri().getHost());
}
代码示例来源:origin: com.ning/async-http-client
private String baseUrl(Uri uri) {
/* 07-Oct-2010, tatu: URL may contain default port number; if so, need to extract
* from base URL.
*/
String scheme = uri.getScheme();
StringBuilder sb = StringUtils.stringBuilder();
sb.append(scheme).append("://").append(uri.getHost());
int port = uri.getPort();
if (scheme.equals("http")) {
if (port == 80)
port = -1;
} else if (scheme.equals("https")) {
if (port == 443)
port = -1;
}
if (port != -1)
sb.append(':').append(port);
if (isNonEmpty(uri.getPath()))
sb.append(uri.getPath());
return sb.toString();
}
代码示例来源:origin: com.ning/async-http-client
public final static String getAuthority(Uri uri) {
int port = uri.getPort() != -1 ? uri.getPort() : getDefaultPort(uri);
return uri.getHost() + ":" + port;
}
代码示例来源:origin: com.ning/async-http-client
private void addHostHeaderIfNeeded(final Request request, final Uri uri,
final HttpRequestPacket requestPacket) {
if (!requestPacket.containsHeader(Header.Host)) {
String host = request.getVirtualHost();
if (host != null) {
requestPacket.addHeader(Header.Host, host);
} else {
if (uri.getPort() == -1) {
requestPacket.addHeader(Header.Host, uri.getHost());
} else {
requestPacket.addHeader(Header.Host, uri.getHost() + ':' + uri.getPort());
}
}
}
}
代码示例来源:origin: com.ning/async-http-client
private 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 == getSchemeDefaultPort(uri.getScheme()) ? host : host + ":" + port;
}
}
代码示例来源:origin: com.ning/async-http-client
private InetSocketAddress remoteAddress(Request request, Uri uri, ProxyServer proxy, boolean useProxy) throws UnknownHostException {
InetAddress address;
int port = getDefaultPort(uri);
if (request.getInetAddress() != null) {
address = request.getInetAddress();
} else if (!useProxy || avoidProxy(proxy, uri.getHost())) {
address = request.getNameResolver().resolve(uri.getHost());
} else {
address = request.getNameResolver().resolve(proxy.getHost());
port = proxy.getPort();
}
return new InetSocketAddress(address, port);
}
代码示例来源:origin: com.ning/async-http-client
private boolean overrideWithContext(Uri context, String originalUrl) {
boolean isRelative = false;
// only use context if the schemes match
if (context != null && (scheme == null || scheme.equalsIgnoreCase(context.getScheme()))) {
// see RFC2396 5.2.3
String contextPath = context.getPath();
if (isNotEmpty(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: com.ning/async-http-client
String host = uri.getHost();
String method = request.getMethod();
urlConnection.setRequestProperty("Connection", ka);
ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request);
boolean avoidProxy = ProxyUtils.avoidProxy(proxyServer, uri.getHost());
if (!avoidProxy) {
if (proxyServer.getPrincipal() != null) {
代码示例来源:origin: com.ning/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);
}
代码示例来源:origin: com.ning/async-http-client
host = request.getVirtualHost();
else
host = uri.getHost();
代码示例来源:origin: com.ning/async-http-client
final Uri uri = request.getUri();
scheme = uri.getScheme();
host = uri.getHost();
port = getPort(scheme, uri.getPort());
代码示例来源:origin: com.ning/async-http-client
final Uri uri = request.getUri();
scheme = uri.getScheme();
host = uri.getHost();
port = getPort(scheme, uri.getPort());
代码示例来源:origin: com.ning/async-http-client
private boolean exitAfterHandlingConnect(//
final Channel channel,//
final NettyResponseFuture<?> future,//
final Request request,//
ProxyServer proxyServer,//
int statusCode,//
HttpRequest httpRequest) throws IOException {
if (statusCode == OK.getCode() && httpRequest.getMethod() == HttpMethod.CONNECT) {
if (future.isKeepAlive())
future.attachChannel(channel, true);
try {
Uri requestUri = request.getUri();
String scheme = requestUri.getScheme();
String host = requestUri.getHost();
int port = getDefaultPort(requestUri);
logger.debug("Connecting to proxy {} for scheme {}", proxyServer, scheme);
channelManager.upgradeProtocol(channel.getPipeline(), scheme, host, port);
} catch (Throwable ex) {
requestSender.abort(channel, future, ex);
}
future.setReuseChannel(true);
future.setConnectAllowed(false);
requestSender.sendNextRequest(new RequestBuilder(future.getRequest()).build(), future);
return true;
}
return false;
}
代码示例来源:origin: com.ning/async-http-client
private Realm kerberosChallenge(Channel channel,//
List<String> authHeaders,//
Request request,//
FluentCaseInsensitiveStringsMap headers,//
Realm realm,//
NettyResponseFuture<?> future) throws NTLMEngineException {
Uri uri = request.getUri();
String host = request.getVirtualHost() == null ? uri.getHost() : request.getVirtualHost();
try {
String challengeHeader = SpnegoEngine.INSTANCE.generateToken(host);
headers.remove(HttpHeaders.Names.AUTHORIZATION);
headers.add(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challengeHeader);
return new Realm.RealmBuilder().clone(realm)//
.setUri(uri)//
.setMethodName(request.getMethod())//
.setScheme(Realm.AuthScheme.KERBEROS)//
.build();
} catch (Throwable throwable) {
String ntlmAuthenticate = getNTLM(authHeaders);
if (ntlmAuthenticate != null) {
return ntlmChallenge(ntlmAuthenticate, request, headers, realm, future);
}
requestSender.abort(channel, future, throwable);
return null;
}
}
代码示例来源:origin: com.ning/async-http-client
uri.getHost(), uri.getPort()));
代码示例来源:origin: com.ning/async-http-client
String origin = "http://" + uri.getHost() + ":" + (uri.getPort() == -1 ? isSecure(uri.getScheme()) ? 443 : 80 : uri.getPort());
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testAbsoluteURIWithContext() {
Uri context = Uri.create("https://hello.com/foo/bar");
Uri url = Uri.create(context, "https://graph.facebook.com/750198471659552/accounts/test-users?method=get&access_token=750198471659552lleveCvbUu_zqBa9tkT3tcgaPh4");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "graph.facebook.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/750198471659552/accounts/test-users");
assertEquals(url.getQuery(), "method=get&access_token=750198471659552lleveCvbUu_zqBa9tkT3tcgaPh4");
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testRelativeUriWithDotsAboveRoot() {
Uri context = Uri.create("https://hello.com/level1");
Uri url = Uri.create(context, "../other/content/img.png");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "hello.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/../other/content/img.png");
assertNull(url.getQuery());
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testRelativeUriWithConsecutiveDotsFromRootResource() {
Uri context = Uri.create("https://hello.com/level1");
Uri url = Uri.create(context, "../../../other/content/img.png");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "hello.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/../../../other/content/img.png");
assertNull(url.getQuery());
}
内容来源于网络,如有侵权,请联系作者删除!