org.asynchttpclient.Response.getHeader()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中org.asynchttpclient.Response.getHeader方法的一些代码示例,展示了Response.getHeader的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getHeader方法的具体详情如下:
包路径:org.asynchttpclient.Response
类名称:Response
方法名:getHeader

Response.getHeader介绍

暂无

代码示例

代码示例来源:origin: AsyncHttpClient/async-http-client

@Override
public Response onCompleted(Response response) {
 logger.debug("ON COMPLETED INVOKED " + response.getHeader("X-KEEP-ALIVE"));
 try {
  assertEquals(response.getStatusCode(), 200);
  remoteAddresses.put(response.getHeader("X-KEEP-ALIVE"), true);
 } finally {
  l.countDown();
 }
 return response;
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Override
 public Response onCompleted(Response response) {
  try {
   assertEquals(response.getStatusCode(), 200);
   assertEquals(response.getHeader("X-Original-Content-Encoding"), "<original encoding>");
  } finally {
   l.countDown();
  }
  return response;
 }
}).get();

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void testUrlRequestParametersEncoding() throws IOException, ExecutionException, InterruptedException {
 String URL = getTargetUrl() + "?q=";
 String REQUEST_PARAM = "github github \ngithub";
 try (AsyncHttpClient client = asyncHttpClient()) {
  String requestUrl2 = URL + URLEncoder.encode(REQUEST_PARAM, UTF_8.name());
  logger.info("Executing request [{}] ...", requestUrl2);
  Response response = client.prepareGet(requestUrl2).execute().get();
  String s = URLDecoder.decode(response.getHeader("q"), UTF_8.name());
  assertEquals(s, REQUEST_PARAM);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void testQueryParameters() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient()) {
  Future<Response> f = client.prepareGet("http://localhost:" + port1).addQueryParam("a", "1").addQueryParam("b", "2").execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertEquals(resp.getHeader("a"), "1");
  assertEquals(resp.getHeader("b"), "2");
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void testParameters() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 String value = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKQLMNOPQRSTUVWXYZ1234567809`~!@#$%^&*()_+-=,.<>/?;:'\"[]{}\\| ";
 try (AsyncHttpClient client = asyncHttpClient()) {
  Future<Response> f = client.preparePost("http://localhost:" + port1).addFormParam("test", value).execute();
  Response resp = f.get(10, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertEquals(resp.getHeader("X-Param"), value.trim());
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void testGlobalProxy() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient(config().setProxyServer(proxyServer("localhost", port1)))) {
  String target = "http://localhost: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: AsyncHttpClient/async-http-client

@Test
public void testRequestLevelProxy() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient()) {
  String target = "http://localhost:1234/";
  Future<Response> f = client.prepareGet(target).setProxyServer(proxyServer("localhost", port1)).execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertEquals(resp.getHeader("target"), "/");
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void urlWithColonTest() throws Exception {
 try (AsyncHttpClient c = asyncHttpClient()) {
  String query = "test:colon:";
  Response response = c.prepareGet(String.format("http://localhost:%d/foo/test/colon?q=%s", port1, query)).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS);
  assertEquals(response.getHeader("q"), query);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void digestAuthTestWithoutScheme() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient()) {
  Future<Response> f = client.prepareGet("http://localhost:" + port1 + "/")
      .setRealm(digestAuthRealm(USER, ADMIN).setRealmName("MyRealm").build())
      .execute();
  Response resp = f.get(60, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertNotNull(resp.getHeader("X-Auth"));
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void basicAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient()) {
  Future<Response> f = client.prepareGet(getTargetUrl())
      .setRealm(basicAuthRealm(USER, ADMIN).build())
      .execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertNotNull(resp.getHeader("X-Auth"));
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void noneAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient()) {
  BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm(basicAuthRealm(USER, 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: AsyncHttpClient/async-http-client

@Test
public void testRequestNonProxyHost() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 ProxyServer proxy = proxyServer("localhost", port1 - 1).setNonProxyHost("localhost").build();
 try (AsyncHttpClient client = asyncHttpClient()) {
  String target = "http://localhost:" + port1 + "/";
  Future<Response> f = client.prepareGet(target).setProxyServer(proxy).execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertEquals(resp.getHeader("target"), "/");
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void digestAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient()) {
  Future<Response> f = client.prepareGet("http://localhost:" + port1 + "/")
      .setRealm(digestAuthRealm(USER, ADMIN).setRealmName("MyRealm").build())
      .execute();
  Response resp = f.get(60, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertNotNull(resp.getHeader("X-Auth"));
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void testBothProxies() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient(config().setProxyServer(proxyServer("localhost", port1 - 1)))) {
  String target = "http://localhost:1234/";
  Future<Response> f = client.prepareGet(target).setProxyServer(proxyServer("localhost", port1)).execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertEquals(resp.getHeader("target"), "/");
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void basicAuthFileTest() throws Exception {
 try (AsyncHttpClient client = asyncHttpClient()) {
  Future<Response> f = client.preparePost(getTargetUrl())
      .setBody(SIMPLE_TEXT_FILE)
      .setRealm(basicAuthRealm(USER, ADMIN).build())
      .execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertNotNull(resp.getHeader("X-Auth"));
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void basicAuthAsyncConfigTest() throws Exception {
 try (AsyncHttpClient client = asyncHttpClient(config().setRealm(basicAuthRealm(USER, ADMIN)))) {
  Future<Response> f = client.preparePost(getTargetUrl())
      .setBody(SIMPLE_TEXT_FILE_STRING)
      .execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertNotNull(resp.getHeader("X-Auth"));
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

private void expectSuccess(Function<BoundRequestBuilder, BoundRequestBuilder> f) throws Exception {
 File file = createTempFile(1024 * 1024);
 try (AsyncHttpClient client = asyncHttpClient()) {
  for (int i = 0; i < 20; i++) {
   Response response = f.apply(client.preparePut(getTargetUrl())
       .addBodyPart(new FilePart("test", file, APPLICATION_OCTET_STREAM.toString(), UTF_8)))
       .execute().get();
   assertEquals(response.getStatusCode(), 200);
   assertEquals(response.getResponseBodyAsBytes().length, Integer.valueOf(response.getHeader("X-" + CONTENT_LENGTH)).intValue());
  }
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void redirectAndBasicAuthTest() throws Exception {
 try (AsyncHttpClient client = asyncHttpClient(config().setFollowRedirect(true).setMaxRedirects(10))) {
  Future<Response> f = client.prepareGet(getTargetUrl2())
      .setRealm(basicAuthRealm(USER, ADMIN).build())
      .execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertNotNull(resp);
  assertNotNull(resp.getHeader("X-Auth"));
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
 public void nonPreemptiveProxyAuthWithHttpsTarget() throws IOException, InterruptedException, ExecutionException {
  try (AsyncHttpClient client = asyncHttpClient(config().setUseInsecureTrustManager(true))) {
   String targetUrl = "https://localhost:" + httpPort + "/foo/bar";
   Request request = get(targetUrl)
       .setProxyServer(proxyServer("127.0.0.1", proxyPort).setRealm(realm(AuthScheme.BASIC, "johndoe", "pass")))
       // .setRealm(realm(AuthScheme.BASIC, "user", "passwd"))
       .build();
   Future<Response> responseFuture = client.executeRequest(request);
   Response response = responseFuture.get();

   Assert.assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
   Assert.assertEquals("/foo/bar", response.getHeader("X-pathInfo"));
  }
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void optionsIsSupported() throws Throwable {
 withClient().run(client ->
  withServer(server).run(server -> {
   server.enqueueEcho();
   Response response = client.prepareOptions(getTargetUrl()).execute().get();
   assertEquals(response.getStatusCode(), 200);
   assertEquals(response.getHeader("Allow"), "GET,HEAD,POST,OPTIONS,TRACE");
  }));
}

相关文章