本文整理汇总了Java中ch.boye.httpclientandroidlib.HttpResponse.getHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse.getHeaders方法的具体用法?Java HttpResponse.getHeaders怎么用?Java HttpResponse.getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.boye.httpclientandroidlib.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.getHeaders方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isNotStale
import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
/**
* Try to detect if the returned response is generated from a stale cache entry.
* @param httpResponse the response to be checked
* @return whether the response is stale or not
*/
private boolean isNotStale(final HttpResponse httpResponse) {
final Header[] warnings = httpResponse.getHeaders(HeaderConstants.WARNING);
if (warnings != null)
{
for (final Header warning : warnings)
{
/**
* warn-codes
* 110 = Response is stale
* 111 = Revalidation failed
*/
final String warningValue = warning.getValue();
if (warningValue.startsWith("110") || warningValue.startsWith("111"))
{
return false;
}
}
}
return true;
}
示例2: getChallenges
import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public Map<String, Header> getChallenges(
final HttpResponse response,
final HttpContext context) throws MalformedChallengeException {
Args.notNull(response, "HTTP response");
final Header[] headers = response.getHeaders(AUTH.WWW_AUTH);
return parseChallenges(headers);
}
示例3: isExplicitlyNonCacheable
import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
protected boolean isExplicitlyNonCacheable(final HttpResponse response) {
final Header[] cacheControlHeaders = response.getHeaders(HeaderConstants.CACHE_CONTROL);
for (final Header header : cacheControlHeaders) {
for (final HeaderElement elem : header.getElements()) {
if (HeaderConstants.CACHE_CONTROL_NO_STORE.equals(elem.getName())
|| HeaderConstants.CACHE_CONTROL_NO_CACHE.equals(elem.getName())
|| (sharedCache && HeaderConstants.PRIVATE.equals(elem.getName()))) {
return true;
}
}
}
return false;
}
示例4: getChallenges
import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public Map<String, Header> getChallenges(
final HttpResponse response,
final HttpContext context) throws MalformedChallengeException {
Args.notNull(response, "HTTP response");
final Header[] headers = response.getHeaders(AUTH.PROXY_AUTH);
return parseChallenges(headers);
}
示例5: isResponseCacheable
import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
/**
* Determines if an HttpResponse can be cached.
*
* @param httpMethod What type of request was this, a GET, PUT, other?
* @param response The origin response
* @return <code>true</code> if response is cacheable
*/
public boolean isResponseCacheable(final String httpMethod, final HttpResponse response) {
boolean cacheable = false;
if (!HeaderConstants.GET_METHOD.equals(httpMethod)) {
log.debug("Response was not cacheable.");
return false;
}
final int status = response.getStatusLine().getStatusCode();
if (cacheableStatuses.contains(status)) {
// these response codes MAY be cached
cacheable = true;
} else if (uncacheableStatuses.contains(status)) {
return false;
} else if (unknownStatusCode(status)) {
// a response with an unknown status code MUST NOT be
// cached
return false;
}
final Header contentLength = response.getFirstHeader(HTTP.CONTENT_LEN);
if (contentLength != null) {
final int contentLengthValue = Integer.parseInt(contentLength.getValue());
if (contentLengthValue > this.maxObjectSizeBytes) {
return false;
}
}
final Header[] ageHeaders = response.getHeaders(HeaderConstants.AGE);
if (ageHeaders.length > 1) {
return false;
}
final Header[] expiresHeaders = response.getHeaders(HeaderConstants.EXPIRES);
if (expiresHeaders.length > 1) {
return false;
}
final Header[] dateHeaders = response.getHeaders(HTTP.DATE_HEADER);
if (dateHeaders.length != 1) {
return false;
}
final Date date = DateUtils.parseDate(dateHeaders[0].getValue());
if (date == null) {
return false;
}
for (final Header varyHdr : response.getHeaders(HeaderConstants.VARY)) {
for (final HeaderElement elem : varyHdr.getElements()) {
if ("*".equals(elem.getName())) {
return false;
}
}
}
if (isExplicitlyNonCacheable(response)) {
return false;
}
return (cacheable || isExplicitlyCacheable(response));
}