本文整理了Java中com.ning.http.client.uri.Uri
类的一些代码示例,展示了Uri
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Uri
类的具体详情如下:
包路径:com.ning.http.client.uri.Uri
类名称:Uri
暂无
代码示例来源: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
public static Uri create(String originalUrl) {
return create(null, originalUrl);
}
代码示例来源:origin: com.ning/async-http-client
public static String computeRealmURI(Uri uri, boolean useAbsoluteURI, boolean omitQuery) {
if (useAbsoluteURI) {
return omitQuery && MiscUtils.isNonEmpty(uri.getQuery()) ? uri.withNewQuery(null).toUrl() : uri.toUrl();
} else {
String path = getNonEmptyPath(uri);
return omitQuery || !MiscUtils.isNonEmpty(uri.getQuery()) ? path : path + "?" + uri.getQuery();
}
}
代码示例来源:origin: com.ning/async-http-client
private void convertToUpgradeRequest(final HttpTransactionContext ctx) {
final Uri requestUri = ctx.requestUri;
ctx.wsRequestURI = requestUri;
ctx.requestUri = requestUri.withNewScheme("ws".equals(requestUri.getScheme()) ? "http" : "https");
}
代码示例来源: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: javaee/grizzly-ahc
@Test
public void testRelativeUriWithDots() {
Uri context = Uri.create("https://hello.com/level1/level2/");
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(), "/level1/other/content/img.png");
assertNull(url.getQuery());
}
代码示例来源:origin: com.ning/async-http-client
final Method method = Method.valueOf(ahcRequest.getMethod());
final Uri uri = req.getUri();
boolean secure = "https".equals(uri.getScheme());
final ProxyServer proxy = httpTxCtx.getProxyServer();
final boolean useProxy = proxy != null;
builder.uri(uri.toUrl());
} else {
builder.uri(AsyncHttpProviderUtils.getNonEmptyPath(uri))
.query(uri.getQuery());
final URI wsURI = httpTxCtx.wsRequestURI.toJavaNetURI();
secure = "wss".equalsIgnoreCase(wsURI.getScheme());
httpTxCtx.protocolHandler = Version.RFC6455.createHandler(true);
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 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
@Override
public String toString() {
// for now, but might change
return toUrl();
}
代码示例来源:origin: com.ning/async-http-client
Uri uri = Uri.create(future.getUri(), location);
future.setUri(uri);
String newUrl = uri.toUrl();
if (request.getUri().getScheme().startsWith(WEBSOCKET)) {
newUrl = newUrl.replaceFirst(HTTP, WEBSOCKET);
代码示例来源: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
public Uri withNewScheme(String newScheme) {
return new Uri(newScheme,//
userInfo,//
host,//
port,//
path,//
query);
}
代码示例来源: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 boolean isWSRequest(final Uri requestUri) {
return requestUri.getScheme().startsWith("ws");
}
代码示例来源:origin: com.virjar/dungproxy-client
@Override
public <T> ListenableFuture<T> execute(Request request, AsyncHandler<T> handler) {
Uri uri = request.getUri();
if (request.getProxyServer() == null) {// 在这里绑定IP池
AvProxy proxy = ipPool.bind(uri.getHost(), uri.toUrl());
if (proxy != null) {
return delegate.execute(new DungProxyRequest(request, proxy),
new DungProxyHandler<>(proxy, handler));
}
}
return delegate.execute(request, handler);
}
代码示例来源:origin: com.ning/async-http-client
private static Request newRequest(final HttpTransactionContext ctx,
final Uri newUri, final HttpResponsePacket response,
final Realm realm, boolean asGet) {
final Request prototype = ctx.getAhcRequest();
final FluentCaseInsensitiveStringsMap prototypeHeaders =
prototype.getHeaders();
prototypeHeaders.remove(Header.Host.toString());
prototypeHeaders.remove(Header.ContentLength.toString());
if (asGet)
prototypeHeaders.remove(Header.ContentType.toString());
if (realm != null && realm.getScheme() == AuthScheme.NTLM) {
prototypeHeaders.remove(Header.Authorization.toString());
prototypeHeaders.remove(Header.ProxyAuthorization.toString());
}
final RequestBuilder builder = new RequestBuilder(prototype);
if (asGet) {
builder.setMethod("GET");
}
builder.setUrl(newUri.toString());
for (String cookieStr : response.getHeaders().values(Header.SetCookie)) {
builder.addOrReplaceCookie(CookieDecoder.decode(cookieStr));
}
return builder.build();
}
代码示例来源:origin: com.ning/async-http-client
private String requestUri(Uri uri, ProxyServer proxyServer, boolean connect) {
if (connect)
return getAuthority(uri);
else if (proxyServer != null && !(useProxyConnect(uri) && config.isUseRelativeURIsWithConnectProxies()))
return uri.toUrl();
else {
String path = getNonEmptyPath(uri);
if (isNonEmpty(uri.getQuery()))
return path + "?" + uri.getQuery();
else
return path;
}
}
代码示例来源:origin: com.ning/async-http-client
public static final int getDefaultPort(Uri uri) {
int port = uri.getPort();
if (port == -1)
port = getSchemeDefaultPort(uri.getScheme());
return port;
}
代码示例来源:origin: com.ning/async-http-client
public ProxyServer select(Uri uri) {
try {
URI javaUri = uri.toJavaNetURI();
内容来源于网络,如有侵权,请联系作者删除!