本文整理汇总了Java中org.apache.http.impl.client.RequestWrapper.resetHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java RequestWrapper.resetHeaders方法的具体用法?Java RequestWrapper.resetHeaders怎么用?Java RequestWrapper.resetHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.impl.client.RequestWrapper
的用法示例。
在下文中一共展示了RequestWrapper.resetHeaders方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildConditionalRequest
import org.apache.http.impl.client.RequestWrapper; //导入方法依赖的package包/类
/**
* When a {@link HttpCacheEntry} is stale but 'might' be used as a response
* to an {@link HttpRequest} we will attempt to revalidate the entry with
* the origin. Build the origin {@link HttpRequest} here and return it.
*
* @param request
* the original request from the caller
* @param cacheEntry
* the entry that needs to be revalidated
* @return the wrapped request
* @throws ProtocolException
* when I am unable to build a new origin request.
*/
public HttpRequest buildConditionalRequest(HttpRequest request,
HttpCacheEntry cacheEntry) throws ProtocolException {
RequestWrapper wrapperRequest = new RequestWrapper(request);
wrapperRequest.resetHeaders();
Header eTag = cacheEntry.getFirstHeader(HeaderConstants.ETAG);
if (eTag != null) {
wrapperRequest.setHeader(HeaderConstants.IF_NONE_MATCH,
eTag.getValue());
}
Header lastModified = cacheEntry
.getFirstHeader(HeaderConstants.LAST_MODIFIED);
if (lastModified != null) {
wrapperRequest.setHeader(HeaderConstants.IF_MODIFIED_SINCE,
lastModified.getValue());
}
boolean mustRevalidate = false;
for (Header h : cacheEntry.getHeaders(HeaderConstants.CACHE_CONTROL)) {
for (HeaderElement elt : h.getElements()) {
if (HeaderConstants.CACHE_CONTROL_MUST_REVALIDATE
.equalsIgnoreCase(elt.getName())
|| HeaderConstants.CACHE_CONTROL_PROXY_REVALIDATE
.equalsIgnoreCase(elt.getName())) {
mustRevalidate = true;
break;
}
}
}
if (mustRevalidate) {
wrapperRequest.addHeader("Cache-Control", "max-age=0");
}
return wrapperRequest;
}
示例2: buildConditionalRequestFromVariants
import org.apache.http.impl.client.RequestWrapper; //导入方法依赖的package包/类
/**
* When a {@link HttpCacheEntry} does not exist for a specific
* {@link HttpRequest} we attempt to see if an existing
* {@link HttpCacheEntry} is appropriate by building a conditional
* {@link HttpRequest} using the variants' ETag values. If no such values
* exist, the request is unmodified
*
* @param request
* the original request from the caller
* @param cacheEntry
* the entry that needs to be revalidated
* @return the wrapped request
* @throws ProtocolException
* when I am unable to build a new origin request.
*/
public HttpRequest buildConditionalRequestFromVariants(HttpRequest request,
Set<HttpCacheEntry> variantEntries) throws ProtocolException {
RequestWrapper wrapperRequest = new RequestWrapper(request);
wrapperRequest.resetHeaders();
// we do not support partial content so all etags are used
StringBuilder etags = new StringBuilder();
boolean first = true;
for (HttpCacheEntry entry : variantEntries) {
Header etagHeader = entry.getFirstHeader(HeaderConstants.ETAG);
if (etagHeader != null) {
if (first) {
etags.append(etagHeader.getValue());
first = false;
} else {
etags.append(",").append(etagHeader.getValue());
}
}
}
// if first is still true than no variants had a cache entry, return
// unmodified wrapped request
if (first) {
return wrapperRequest;
}
wrapperRequest.setHeader(HeaderConstants.IF_NONE_MATCH,
etags.toString());
return wrapperRequest;
}
示例3: buildUnconditionalRequest
import org.apache.http.impl.client.RequestWrapper; //导入方法依赖的package包/类
/**
* Returns a request to unconditionally validate a cache entry with the
* origin. In certain cases (due to multiple intervening caches) our cache
* may actually receive a response to a normal conditional validation where
* the Date header is actually older than that of our current cache entry.
* In this case, the protocol recommendation is to retry the validation and
* force syncup with the origin.
*
* @param request
* client request we are trying to satisfy
* @param entry
* existing cache entry we are trying to validate
* @return an unconditional validation request
* @throws ProtocolException
*/
public HttpRequest buildUnconditionalRequest(HttpRequest request,
HttpCacheEntry entry) throws ProtocolException {
RequestWrapper wrapped = new RequestWrapper(request);
wrapped.resetHeaders();
wrapped.addHeader("Cache-Control", "no-cache");
wrapped.addHeader("Pragma", "no-cache");
wrapped.removeHeaders("If-Range");
wrapped.removeHeaders("If-Match");
wrapped.removeHeaders("If-None-Match");
wrapped.removeHeaders("If-Unmodified-Since");
wrapped.removeHeaders("If-Modified-Since");
return wrapped;
}