本文整理了Java中com.ning.http.client.Response.getHeader
方法的一些代码示例,展示了Response.getHeader
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getHeader
方法的具体详情如下:
包路径:com.ning.http.client.Response
类名称:Response
方法名:getHeader
[英]Return the response header
[中]返回响应头
代码示例来源:origin: com.ning/async-http-client
public String getHeader(String name) {
return response.getHeader(name);
}
代码示例来源:origin: play/play-java
/**
* Get the given HTTP header of the response
*/
public String getHeader(String key) {
return ahcResponse.getHeader(key);
}
代码示例来源:origin: resthub/resthub-spring-stack
/**
* Get the given HTTP header of the response
*/
public String getHeader(String key) {
return ahcResponse.getHeader(key);
}
代码示例来源:origin: killbilling/recurly-java-library
public ResponseMetadata(Response response) {
this.requestId = response.getHeader("X-Request-Id");
this.cfRay = response.getHeader("CF-RAY");
this.statusCode = response.getStatusCode();
}
代码示例来源:origin: taskadapter/trello-java-wrapper
@Override
public URI onCompleted(Response response) throws Exception {
String location = response.getHeader("Location");
if (location != null) {
return URI.create(location);
} else {
throw new TrelloHttpException("Location header not set");
}
}
代码示例来源:origin: com.julienvey.trello/trello-java-wrapper
@Override
public URI onCompleted(Response response) throws Exception {
String location = response.getHeader("Location");
if (location != null) {
return URI.create(location);
} else {
throw new TrelloHttpException("Location header not set");
}
}
代码示例来源:origin: spotify/async-datastore-client
private InputStream streamResponse(final Response response) throws IOException {
final InputStream input = response.getResponseBodyAsStream();
final boolean compressed = "gzip".equals(response.getHeader("Content-Encoding"));
return compressed ? new GZIPInputStream(input) : input;
}
代码示例来源:origin: io.sphere.sdk.jvm/sdk-http-ahc-1_8
private byte[] getResponseBodyAsBytes(final Response response) {
try {
final boolean gzipEncoded =
Optional.ofNullable(response.getHeader(HttpHeaders.CONTENT_ENCODING))
.map(v -> v.equalsIgnoreCase("gzip"))
.orElse(false);
return gzipEncoded ? unzip(response) : response.getResponseBodyAsBytes();
} catch (IOException e) {
throw new HttpException(e);
}
}
代码示例来源:origin: com.commercetools.sdk.jvm.core/sdk-http-ahc-1_8
private byte[] getResponseBodyAsBytes(final Response response) {
try {
final boolean gzipEncoded =
Optional.ofNullable(response.getHeader(HttpHeaders.CONTENT_ENCODING))
.map(v -> v.equalsIgnoreCase("gzip"))
.orElse(false);
return gzipEncoded ? unzip(response) : response.getResponseBodyAsBytes();
} catch (IOException e) {
throw new HttpException(e);
}
}
代码示例来源:origin: javaee/grizzly-ahc
@Override
public Response onCompleted(Response response) throws Exception {
try {
Assert.assertTrue(response.getHeader("X-pathInfo") != null);
Assert.assertTrue(response.getHeader("X-queryString") != null);
} finally {
l.countDown();
}
return response;
}
};
代码示例来源:origin: javaee/grizzly-ahc
@Override
public Response onCompleted(Response response) throws Exception {
try {
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getHeader("Transfer-Encoding"), "chunked");
} finally {
l.countDown();
}
return response;
}
}).get();
代码示例来源:origin: javaee/grizzly-ahc
@Override
public Response onCompleted(Response response) throws Exception {
try {
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getHeader("Upgrade"), "h2,h2c");
} finally {
l.countDown();
}
return response;
}
}).get();
代码示例来源:origin: javaee/grizzly-ahc
@Test(groups = { "standalone", "default_provider" })
public void urlWithColonTest() throws Throwable {
try (AsyncHttpClient client = getAsyncHttpClient(null)) {
String query = "test:colon:";
Response response = client.prepareGet(String.format("http://127.0.0.1:%d/foo/test/colon?q=%s", port1, query)).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS);
assertEquals(response.getHeader("q"), query);
}
}
}
代码示例来源:origin: javaee/grizzly-ahc
@Test(groups = { "standalone", "default_provider" })
public void testNonProxyHostIssue202() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = getAsyncHttpClient(null)) {
String target = "http://127.0.0.1:" + port1 + "/";
Future<Response> f = client.prepareGet(target).setProxyServer(new ProxyServer("127.0.0.1", port1 - 1).addNonProxyHost("127.0.0.1")).execute();
Response resp = f.get(3, TimeUnit.SECONDS);
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("target"), "/");
}
}
代码示例来源:origin: javaee/grizzly-ahc
@Test(groups = { "standalone", "default_provider" })
public void testGlobalProxy() throws IOException, ExecutionException, TimeoutException, InterruptedException {
AsyncHttpClientConfig cfg = new AsyncHttpClientConfig.Builder().setProxyServer(new ProxyServer("127.0.0.1", port1)).build();
try (AsyncHttpClient client = getAsyncHttpClient(cfg)) {
String target = "http://127.0.0.1:1234/";
Future<Response> f = client.prepareGet(target).execute();
Response resp = f.get(3, TimeUnit.SECONDS);
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("target"), "/");
}
}
代码示例来源:origin: javaee/grizzly-ahc
@Test(groups = { "standalone", "default_provider" })
public void digestAuthTestWithoutScheme() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = getAsyncHttpClient(null)) {
AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1:" + port1 + "/").setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).setRealmName("MyRealm").build());
Future<Response> f = r.execute();
Response resp = f.get(60, TimeUnit.SECONDS);
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertNotNull(resp.getHeader("X-Auth"));
}
}
代码示例来源:origin: javaee/grizzly-ahc
@Test(groups = { "standalone", "default_provider" })
public void basicAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = getAsyncHttpClient(null)) {
AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).build());
Future<Response> f = r.execute();
Response resp = f.get(3, TimeUnit.SECONDS);
assertNotNull(resp);
assertNotNull(resp.getHeader("X-Auth"));
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
}
}
代码示例来源:origin: javaee/grizzly-ahc
@Test(groups = { "standalone", "default_provider" })
public void digestAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = getAsyncHttpClient(null)) {
AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1:" + port1 + "/").setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).setRealmName("MyRealm").setScheme(Realm.AuthScheme.DIGEST).build());
Future<Response> f = r.execute();
Response resp = f.get(60, TimeUnit.SECONDS);
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertNotNull(resp.getHeader("X-Auth"));
}
}
代码示例来源:origin: javaee/grizzly-ahc
@Test(groups = { "default_provider", "async" })
public void optionsTest() throws Throwable {
try (AsyncHttpClient client = getAsyncHttpClient(new Builder().build())) {
Response r = client.prepareOptions(getTargetUrl()).execute().get();
assertEquals(r.getStatusCode(), 200);
assertEquals(r.getHeader("Allow"), "GET,HEAD,POST,OPTIONS,TRACE");
}
}
代码示例来源:origin: javaee/grizzly-ahc
private void doTest(boolean usePreemptiveAuth) throws UnknownHostException, InterruptedException, ExecutionException
{
try (AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().build())) {
Request request = new RequestBuilder("GET").setProxyServer(basicProxy()).setUrl(getTargetUrl()).setRealm(
new Realm.RealmBuilder().setPrincipal("user").setPassword("passwd").setScheme(BASIC).setUsePreemptiveAuth(usePreemptiveAuth).build()).build();
Future<Response> responseFuture = client.executeRequest(request);
Response response = responseFuture.get();
Assert.assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
Assert.assertTrue(getTargetUrl().endsWith(response.getHeader("target")));
}
}
内容来源于网络,如有侵权,请联系作者删除!