本文整理了Java中org.apache.hc.core5.http.Header.getValue()
方法的一些代码示例,展示了Header.getValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Header.getValue()
方法的具体详情如下:
包路径:org.apache.hc.core5.http.Header
类名称:Header
方法名:getValue
暂无
代码示例来源:origin: apache/httpcomponents-client
static boolean responseAndEntryEtagsDiffer(final HttpResponse response,
final HttpCacheEntry entry) {
final Header entryEtag = entry.getFirstHeader(HeaderConstants.ETAG);
final Header responseEtag = response.getFirstHeader(HeaderConstants.ETAG);
if (entryEtag == null || responseEtag == null) {
return false;
}
return (!entryEtag.getValue().equals(responseEtag.getValue()));
}
代码示例来源:origin: apache/httpcomponents-client
private boolean hasValidDateField(final HttpRequest request, final String headerName) {
for(final Header h : request.getHeaders(headerName)) {
final Date date = DateUtils.parseDate(h.getValue());
return date != null;
}
return false;
}
}
代码示例来源:origin: apache/httpcomponents-client
private void requestDidNotExpect100ContinueButResponseIsOne(
final HttpRequest originalRequest, final HttpResponse response) throws IOException {
if (response.getCode() != HttpStatus.SC_CONTINUE) {
return;
}
final Header header = originalRequest.getFirstHeader(HttpHeaders.EXPECT);
if (header != null && header.getValue().equalsIgnoreCase(HeaderElements.CONTINUE)) {
return;
}
throw new ClientProtocolException(UNEXPECTED_100_CONTINUE);
}
代码示例来源:origin: apache/httpcomponents-client
private void headersNotContain(final Header[] headers, final String name, final String value) {
for (final Header header : headers) {
if (header.getName().equals(name)) {
if (header.getValue().equals(value)) {
fail("Header [" + name + ": " + value + "] found in headers where it should not be");
}
}
}
}
}
代码示例来源:origin: apache/httpcomponents-client
private void headersContain(final Header[] headers, final String name, final String value) {
for (final Header header : headers) {
if (header.getName().equals(name)) {
if (header.getValue().equals(value)) {
return;
}
}
}
fail("Header [" + name + ": " + value + "] not found in headers.");
}
代码示例来源:origin: apache/httpcomponents-client
@Test
public void testResponseHasContentLength() throws Exception {
final byte[] buf = new byte[] { 1, 2, 3, 4, 5 };
final HttpCacheEntry entry1 = HttpTestUtils.makeCacheEntry(buf);
final SimpleHttpResponse response = impl.generateResponse(request, entry1);
final Header length = response.getFirstHeader("Content-Length");
Assert.assertNotNull("Content-Length Header is missing", length);
Assert.assertEquals("Content-Length does not match buffer length", buf.length, Integer
.parseInt(length.getValue()));
}
代码示例来源:origin: apache/httpcomponents-client
@Test
public void testAgeHeaderIsPopulatedWithCurrentAgeOfCacheEntryIfNonZero() throws Exception {
currentAge(10L);
final SimpleHttpResponse response = impl.generateResponse(request, entry);
verify(mockValidityPolicy).getCurrentAgeSecs(same(entry), isA(Date.class));
final Header ageHdr = response.getFirstHeader("Age");
Assert.assertNotNull(ageHdr);
Assert.assertEquals(10L, Long.parseLong(ageHdr.getValue()));
}
代码示例来源:origin: apache/httpcomponents-client
private void testDoesNotModifyHeaderOnResponses(final String headerName) throws Exception {
final String headerValue = HttpTestUtils
.getCanonicalHeaderValue(originResponse, headerName);
backendExpectsAnyRequest().andReturn(originResponse);
replayMocks();
final ClassicHttpResponse result = execute(request);
verifyMocks();
assertEquals(headerValue,
result.getFirstHeader(headerName).getValue());
}
代码示例来源:origin: apache/httpcomponents-client
@Test
public void testBuildUnconditionalRequestCarriesOtherRequestHeaders()
throws Exception {
request.addHeader("User-Agent","MyBrowser/1.0");
final HttpRequest result = impl.buildUnconditionalRequest(request);
Assert.assertEquals("MyBrowser/1.0",
result.getFirstHeader("User-Agent").getValue());
}
代码示例来源:origin: apache/httpcomponents-client
@Test
public void testAgeHeaderIsPopulatedWithMaxAgeIfCurrentAgeTooBig() throws Exception {
currentAge(CacheValidityPolicy.MAX_AGE + 1L);
final SimpleHttpResponse response = impl.generateResponse(request, entry);
verify(mockValidityPolicy).getCurrentAgeSecs(same(entry), isA(Date.class));
final Header ageHdr = response.getFirstHeader("Age");
Assert.assertNotNull(ageHdr);
Assert.assertEquals(CacheValidityPolicy.MAX_AGE, Long.parseLong(ageHdr.getValue()));
}
代码示例来源:origin: apache/httpcomponents-client
private void testDoesNotModifyHeaderFromOrigin(final String header, final String value) throws Exception {
originResponse = HttpTestUtils.make200Response();
originResponse.setHeader(header, value);
backendExpectsAnyRequest().andReturn(originResponse);
replayMocks();
final ClassicHttpResponse result = execute(request);
verifyMocks();
Assert.assertEquals(value, result.getFirstHeader(header).getValue());
}
代码示例来源:origin: apache/httpcomponents-client
@Test
public void testTransmitsAgeHeaderIfIncomingAgeHeaderTooBig() throws Exception {
final String reallyOldAge = "1" + Long.MAX_VALUE;
originResponse.setHeader("Age",reallyOldAge);
backendExpectsAnyRequest().andReturn(originResponse);
replayMocks();
final ClassicHttpResponse result = execute(request);
verifyMocks();
Assert.assertEquals("2147483648",
result.getFirstHeader("Age").getValue());
}
代码示例来源:origin: apache/httpcomponents-client
private void testDoesNotModifyHeaderFromOriginResponseWithNoTransform(final String header, final String value) throws Exception {
originResponse.addHeader("Cache-Control","no-transform");
originResponse.setHeader(header, value);
backendExpectsAnyRequest().andReturn(originResponse);
replayMocks();
final ClassicHttpResponse result = execute(request);
verifyMocks();
Assert.assertEquals(value, result.getFirstHeader(header).getValue());
}
代码示例来源:origin: apache/httpcomponents-client
@Test
public void testRetainsWarningHeadersReceivedFromUpstream() throws Exception {
originResponse.removeHeaders("Warning");
final String warning = "199 fred \"misc\"";
originResponse.addHeader("Warning", warning);
backendExpectsAnyRequest().andReturn(originResponse);
replayMocks();
final ClassicHttpResponse result = execute(request);
verifyMocks();
Assert.assertEquals(warning,
result.getFirstHeader("Warning").getValue());
}
代码示例来源: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 testGetFirstHeaderReturnsCorrectHeader() {
final Header[] headers = { new BasicHeader("foo", "fooValue"),
new BasicHeader("bar", "barValue1"),
new BasicHeader("bar", "barValue2")
};
entry = makeEntry(headers);
assertEquals("barValue1", entry.getFirstHeader("bar").getValue());
}
代码示例来源: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 stripsMinFreshFromRequestIfNoCachePresent()
throws Exception {
final HttpRequest req = new BasicHttpRequest("GET", "/");
req.setHeader("Cache-Control", "no-cache, min-fresh=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 stripsMaxFreshFromRequestIfNoCachePresent()
throws Exception {
final HttpRequest req = new BasicHttpRequest("GET", "/");
req.setHeader("Cache-Control", "no-cache, max-stale=10");
final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req);
impl.makeRequestCompliant(wrapper);
assertEquals("no-cache",
wrapper.getFirstHeader("Cache-Control").getValue());
}
代码示例来源:origin: apache/httpcomponents-client
private void testDoesNotModifyHeaderOnCachedResponseWithNoTransform(final String header, final String value) throws Exception {
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
originResponse.addHeader("Cache-Control","max-age=3600, no-transform");
originResponse.setHeader(header, value);
backendExpectsAnyRequest().andReturn(originResponse);
replayMocks();
execute(req1);
final ClassicHttpResponse result = execute(req2);
verifyMocks();
Assert.assertEquals(value, result.getFirstHeader(header).getValue());
}
内容来源于网络,如有侵权,请联系作者删除!