本文整理了Java中org.apache.hc.core5.http.HttpRequest.getAuthority()
方法的一些代码示例,展示了HttpRequest.getAuthority()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.getAuthority()
方法的具体详情如下:
包路径:org.apache.hc.core5.http.HttpRequest
类名称:HttpRequest
方法名:getAuthority
[英]Returns authority of this request message.
[中]返回此请求消息的权限。
代码示例来源:origin: apache/httpcomponents-client
Args.notNull(target, "Target");
final StringBuilder buf = new StringBuilder();
final URIAuthority authority = request.getAuthority();
if (authority != null) {
final String scheme = request.getScheme();
代码示例来源:origin: apache/httpcomponents-client
final URIAuthority authority = request.getAuthority();
if (authority != null) {
spn = "HTTP/" + authority.getHostName();
代码示例来源:origin: apache/httpcomponents-core
@Override
public URIAuthority getAuthority() {
return message.getAuthority();
}
代码示例来源:origin: org.apache.httpcomponents.core5/httpcore5
@Override
public URIAuthority getAuthority() {
return message.getAuthority();
}
代码示例来源:origin: apache/httpcomponents-client
@Override
public void handleRequest(
final HttpRequest request,
final EntityDetails entityDetails,
final ResponseChannel responseChannel,
final HttpContext context) throws HttpException, IOException {
final Header h = request.getFirstHeader(HttpHeaders.AUTHORIZATION);
final String challengeResponse = h != null ? authTokenExtractor.extract(h.getValue()) : null;
final URIAuthority authority = request.getAuthority();
final String requestUri = request.getRequestUri();
final boolean authenticated = authenticator.authenticate(authority, requestUri, challengeResponse);
final Header expect = request.getFirstHeader(HttpHeaders.EXPECT);
final boolean expectContinue = expect != null && "100-continue".equalsIgnoreCase(expect.getValue());
if (authenticated) {
if (expectContinue) {
responseChannel.sendInformation(new BasicClassicHttpResponse(HttpStatus.SC_CONTINUE), context);
}
exchangeHandler.handleRequest(request, entityDetails, responseChannel, context);
} else {
final HttpResponse unauthorized = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED);
final String realm = authenticator.getRealm(authority, requestUri);
unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"" + realm + "\"");
customizeUnauthorizedResponse(unauthorized);
final AsyncResponseProducer responseProducer = new BasicResponseProducer(
unauthorized,
new BasicAsyncEntityProducer("Unauthorized", ContentType.TEXT_PLAIN));
responseProducerRef.set(responseProducer);
responseProducer.sendResponse(responseChannel, context);
}
}
代码示例来源:origin: apache/httpcomponents-client
context.setAttribute(HttpClientContext.HTTP_REQUEST, request);
final URIAuthority authority = request.getAuthority();
final String scheme = request.getScheme();
final HttpHost target = authority != null ? new HttpHost(scheme, authority) : route.getTargetHost();
代码示例来源:origin: org.apache.httpcomponents.core5/httpcore5
@Override
public T resolve(final HttpRequest request, final HttpContext context) throws MisdirectedRequestException {
final URIAuthority authority = request.getAuthority();
final String key = authority != null ? authority.getHostName().toLowerCase(Locale.ROOT) : null;
final LookupRegistry<T> patternMatcher = getPatternMatcher(key);
if (patternMatcher == null) {
throw new MisdirectedRequestException("Not authoritative");
}
String path = request.getPath();
final int i = path.indexOf('?');
if (i != -1) {
path = path.substring(0, i);
}
return patternMatcher.lookup(path);
}
代码示例来源:origin: apache/httpcomponents-core
@Override
public T resolve(final HttpRequest request, final HttpContext context) throws MisdirectedRequestException {
final URIAuthority authority = request.getAuthority();
final String key = authority != null ? authority.getHostName().toLowerCase(Locale.ROOT) : null;
final LookupRegistry<T> patternMatcher = getPatternMatcher(key);
if (patternMatcher == null) {
throw new MisdirectedRequestException("Not authoritative");
}
String path = request.getPath();
final int i = path.indexOf('?');
if (i != -1) {
path = path.substring(0, i);
}
return patternMatcher.lookup(path);
}
代码示例来源:origin: org.apache.httpcomponents.client5/httpclient5
public static HttpHost determineHost(final HttpRequest request) throws HttpException {
if (request == null) {
return null;
}
final URIAuthority authority = request.getAuthority();
if (authority != null) {
final String scheme = request.getScheme();
if (scheme == null) {
throw new ProtocolException("Protocol scheme is not specified");
}
return new HttpHost(scheme, authority);
}
return null;
}
代码示例来源:origin: org.apache.httpcomponents.client5/httpclient5
@Override
public HttpRequest copy(final HttpRequest original) {
if (original == null) {
return null;
}
final BasicHttpRequest copy = new BasicHttpRequest(original.getMethod(), original.getPath());
copy.setVersion(original.getVersion());
for (final Iterator<Header> it = original.headerIterator(); it.hasNext(); ) {
copy.addHeader(it.next());
}
copy.setScheme(original.getScheme());
copy.setAuthority(original.getAuthority());
return copy;
}
代码示例来源:origin: org.apache.httpcomponents.client5/httpclient5
public static SimpleHttpRequest copy(final HttpRequest original) {
Args.notNull(original, "HTTP request");
final SimpleHttpRequest copy = new SimpleHttpRequest(original.getMethod(), original.getRequestUri());
copy.setVersion(original.getVersion());
for (final Iterator<Header> it = original.headerIterator(); it.hasNext(); ) {
copy.addHeader(it.next());
}
copy.setScheme(original.getScheme());
copy.setAuthority(original.getAuthority());
return copy;
}
代码示例来源:origin: apache/httpcomponents-core
@Test
public void testRequestWithRelativeURI() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", new URI("/stuff"));
Assert.assertEquals("GET", request.getMethod());
Assert.assertEquals("/stuff", request.getPath());
Assert.assertEquals(null, request.getAuthority());
Assert.assertEquals(new URI("/stuff"), request.getUri());
}
代码示例来源:origin: apache/httpcomponents-core
@Test
public void testRequestWithAbsoluteURI() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", new URI("https://host:9443/stuff?param=value"));
Assert.assertEquals("GET", request.getMethod());
Assert.assertEquals("/stuff?param=value", request.getPath());
Assert.assertEquals(new URIAuthority("host", 9443), request.getAuthority());
Assert.assertEquals("https", request.getScheme());
Assert.assertEquals(new URI("https://host:9443/stuff?param=value"), request.getUri());
}
代码示例来源:origin: org.apache.httpcomponents.client5/httpclient5
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;
}
代码示例来源:origin: apache/httpcomponents-core
@Test
public void testRequestWithNoPath() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", new URI("http://host"));
Assert.assertEquals("GET", request.getMethod());
Assert.assertEquals("/", request.getPath());
Assert.assertEquals(new URIAuthority("host"), request.getAuthority());
Assert.assertEquals("http", request.getScheme());
Assert.assertEquals(new URI("http://host/"), request.getUri());
}
代码示例来源:origin: apache/httpcomponents-core
@Test
public void testRequestWithUserInfo() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", new URI("https://user:pwd@host:9443/stuff?param=value"));
Assert.assertEquals("GET", request.getMethod());
Assert.assertEquals("/stuff?param=value", request.getPath());
Assert.assertEquals(new URIAuthority("user:pwd", "host", 9443), request.getAuthority());
Assert.assertEquals("https", request.getScheme());
Assert.assertEquals(new URI("https://host:9443/stuff?param=value"), request.getUri());
}
代码示例来源:origin: apache/httpcomponents-core
@Test
public void testRequestBasics() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/stuff");
Assert.assertEquals("GET", request.getMethod());
Assert.assertEquals("/stuff", request.getPath());
Assert.assertEquals(null, request.getAuthority());
Assert.assertEquals(new URI("/stuff"), request.getUri());
}
代码示例来源:origin: apache/httpcomponents-core
@Test
public void testRequestWithAbsoluteURIAsPath() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "https://host:9443/stuff?param=value");
Assert.assertEquals("GET", request.getMethod());
Assert.assertEquals("/stuff?param=value", request.getPath());
Assert.assertEquals(new URIAuthority("host", 9443), request.getAuthority());
Assert.assertEquals("https", request.getScheme());
Assert.assertEquals(new URI("https://host:9443/stuff?param=value"), request.getUri());
}
代码示例来源:origin: apache/httpcomponents-core
@Test
public void testRequestWithAuthorityRelativePath() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", new HttpHost("http", "somehost", -1), "stuff");
Assert.assertEquals("GET", request.getMethod());
Assert.assertEquals("stuff", request.getPath());
Assert.assertEquals(new URIAuthority("somehost"), request.getAuthority());
Assert.assertEquals(new URI("http://somehost/stuff"), request.getUri());
}
代码示例来源:origin: apache/httpcomponents-core
@Test
public void testRequestWithAuthority() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", new HttpHost("http", "somehost", -1), "/stuff");
Assert.assertEquals("GET", request.getMethod());
Assert.assertEquals("/stuff", request.getPath());
Assert.assertEquals(new URIAuthority("somehost"), request.getAuthority());
Assert.assertEquals(new URI("http://somehost/stuff"), request.getUri());
}
内容来源于网络,如有侵权,请联系作者删除!