org.apache.hc.core5.http.HttpRequest.setHeader()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(288)

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

HttpRequest.setHeader介绍

暂无

代码示例

代码示例来源:origin: apache/httpcomponents-client

private void decrementOPTIONSMaxForwardsIfGreaterThen0(final HttpRequest request) {
  if (!HeaderConstants.OPTIONS_METHOD.equals(request.getMethod())) {
    return;
  }
  final Header maxForwards = request.getFirstHeader(HeaderConstants.MAX_FORWARDS);
  if (maxForwards == null) {
    return;
  }
  request.removeHeaders(HeaderConstants.MAX_FORWARDS);
  final int currentMaxForwards = Integer.parseInt(maxForwards.getValue());
  request.setHeader(HeaderConstants.MAX_FORWARDS, Integer.toString(currentMaxForwards - 1));
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testDoesNotInvalidateRequestsWithClientCacheControlHeaders() throws Exception {
  final HttpRequest request = new BasicHttpRequest("GET","/");
  request.setHeader("Cache-Control","no-cache");
  impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
  verify(mockStorage).getEntry(ArgumentMatchers.eq("http://foo.example.com:80/"), ArgumentMatchers.<FutureCallback<HttpCacheEntry>>any());
  verifyNoMoreInteractions(mockStorage);
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testDoesNotInvalidateRequestsWithClientPragmaHeaders() throws Exception {
  final HttpRequest request = new BasicHttpRequest("GET","/");
  request.setHeader("Pragma","no-cache");
  impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
  verify(mockStorage).getEntry(ArgumentMatchers.eq("http://foo.example.com:80/"), ArgumentMatchers.<FutureCallback<HttpCacheEntry>>any());
  verifyNoMoreInteractions(mockStorage);
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testDoesNotInvalidateRequestsWithClientCacheControlHeaders() throws Exception {
  final HttpRequest request = new BasicHttpRequest("GET","/");
  request.setHeader("Cache-Control","no-cache");
  impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
  verify(mockStorage).getEntry("http://foo.example.com:80/");
  verifyNoMoreInteractions(mockStorage);
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testRequestWithWeekETagForPUTOrDELETEIfMatch() throws Exception {
  final HttpRequest req = new BasicHttpRequest("PUT", "http://example.com/");
  req.setHeader("If-Match", "W/\"weak\"");
  assertEquals(1, impl.requestIsFatallyNonCompliant(req).size());
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testRequestContainsNoCacheDirectiveWithFieldName() throws Exception {
  final HttpRequest req = new BasicHttpRequest("GET", "/");
  req.setHeader("Cache-Control", "no-cache=false");
  assertEquals(1, impl.requestIsFatallyNonCompliant(req).size());
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testRequestWithWeekETagForPUTOrDELETEIfMatchAllowed() throws Exception {
  final HttpRequest req = new BasicHttpRequest("PUT", "http://example.com/");
  req.setHeader("If-Match", "W/\"weak\"");
  impl = new RequestProtocolCompliance(true);
  assertEquals(Arrays.asList(), impl.requestIsFatallyNonCompliant(req));
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testResponsesToRequestsWithNoStoreAreNotCacheable() {
  request.setHeader("Cache-Control","no-store");
  response.setHeader("Cache-Control","public");
  Assert.assertFalse(policy.isResponseCacheable(request,response));
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testAuthorizedResponsesWithCacheControlPublicAreCacheable() {
  request = new BasicHttpRequest("GET","/");
  request.setHeader("Authorization","Basic dXNlcjpwYXNzd2Q=");
  response.setHeader("Cache-Control","public");
  Assert.assertTrue(policy.isResponseCacheable(request,response));
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testAuthorizedResponsesWithCacheControlMaxAgeAreNotCacheable() {
  request = new BasicHttpRequest("GET","/");
  request.setHeader("Authorization","Basic dXNlcjpwYXNzd2Q=");
  response.setHeader("Cache-Control","max-age=3600");
  Assert.assertFalse(policy.isResponseCacheable(request,response));
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testVaryStarIsNotCacheableUsingSharedPublicCache() {
  policy = new ResponseCachingPolicy(0, true, false, false);
  request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
  response.setHeader("Cache-Control", "public");
  response.setHeader("Vary", "*");
  Assert.assertFalse(policy.isResponseCacheable(request, response));
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void test206ResponseCodeIsNotCacheableUsingSharedPublicCache() {
  policy = new ResponseCachingPolicy(0, true, false, false);
  request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
  response.setCode(HttpStatus.SC_PARTIAL_CONTENT);
  response.setHeader("Cache-Control", "public");
  Assert.assertFalse(policy.isResponseCacheable(request, response));
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void correctlyStripsMinFreshFromMiddleIfNoCache()
  throws Exception {
  final HttpRequest req = new BasicHttpRequest("GET", "/");
  req.setHeader("Cache-Control", "no-cache,min-fresh=10,no-store");
  final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req);
  impl.makeRequestCompliant(wrapper);
  assertEquals("no-cache,no-store",
      wrapper.getFirstHeader("Cache-Control").getValue());
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testResponsesWithMultipleAgeHeadersAreNotCacheableUsingSharedPublicCache() {
  policy = new ResponseCachingPolicy(0, true, false, false);
  request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
  response.setHeader("Cache-Control", "public");
  response.addHeader("Age", "3");
  response.addHeader("Age", "5");
  Assert.assertFalse(policy.isResponseCacheable(request, response));
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void stripsMaxAgeFromRequestIfNoCachePresent()
  throws Exception {
  final HttpRequest req = new BasicHttpRequest("GET", "/");
  req.setHeader("Cache-Control", "no-cache, max-age=10");
  final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req);
  impl.makeRequestCompliant(wrapper);
  assertEquals("no-cache",
      wrapper.getFirstHeader("Cache-Control").getValue());
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void doesNotStripMinFreshFromRequestWithoutNoCache()
  throws Exception {
  final HttpRequest req = new BasicHttpRequest("GET", "/");
  req.setHeader("Cache-Control", "min-fresh=10");
  final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req);
  impl.makeRequestCompliant(wrapper);
  assertEquals("min-fresh=10",
      wrapper.getFirstHeader("Cache-Control").getValue());
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testMayReturnStaleIfErrorInRequestIsTrueWithinStaleness(){
  final Header[] headers = new Header[] {
      new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
      new BasicHeader("Cache-Control", "max-age=5")
  };
  final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, now, headers);
  final HttpRequest req = new BasicHttpRequest("GET","/");
  req.setHeader("Cache-Control","stale-if-error=15");
  assertTrue(impl.mayReturnStaleIfError(req, entry, now));
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testMayNotReturnStaleIfErrorInResponseAndAfterRequestWindow(){
  final Header[] headers = new Header[] {
      new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
      new BasicHeader("Cache-Control", "max-age=5")
  };
  final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, now, headers);
  final HttpRequest req = new BasicHttpRequest("GET","/");
  req.setHeader("Cache-Control","stale-if-error=1");
  assertFalse(impl.mayReturnStaleIfError(req, entry, now));
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testResponsesWithMultipleDateHeadersAreNotCacheableUsingSharedPublicCache() {
  policy = new ResponseCachingPolicy(0, true, false, false);
  request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
  response.setHeader("Cache-Control", "public");
  response.addHeader("Date", DateUtils.formatDate(now));
  response.addHeader("Date", DateUtils.formatDate(sixSecondsAgo));
  Assert.assertFalse(policy.isResponseCacheable(request, response));
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testResponsesWithMultipleExpiresHeadersAreNotCacheableUsingSharedPublicCache() {
  policy = new ResponseCachingPolicy(0, true, false, false);
  request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
  response.setHeader("Cache-Control", "public");
  response.addHeader("Expires", DateUtils.formatDate(now));
  response.addHeader("Expires", DateUtils.formatDate(sixSecondsAgo));
  Assert.assertFalse(policy.isResponseCacheable(request, response));
}

相关文章