本文整理了Java中org.apache.hc.core5.http.HttpRequest.containsHeader()
方法的一些代码示例,展示了HttpRequest.containsHeader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.containsHeader()
方法的具体详情如下:
包路径:org.apache.hc.core5.http.HttpRequest
类名称:HttpRequest
方法名:containsHeader
暂无
代码示例来源:origin: apache/httpcomponents-client
private boolean hasSupportedEtagValidator(final HttpRequest request) {
return request.containsHeader(HeaderConstants.IF_NONE_MATCH);
}
代码示例来源:origin: apache/httpcomponents-client
SimpleHttpResponse generateCachedResponse(
final HttpRequest request,
final HttpContext context,
final HttpCacheEntry entry,
final Date now) throws ResourceIOException {
final SimpleHttpResponse cachedResponse;
if (request.containsHeader(HeaderConstants.IF_NONE_MATCH)
|| request.containsHeader(HeaderConstants.IF_MODIFIED_SINCE)) {
cachedResponse = responseGenerator.generateNotModifiedResponse(entry);
} else {
cachedResponse = responseGenerator.generateResponse(request, entry);
}
setResponseStatus(context, CacheResponseStatus.CACHE_HIT);
if (validityPolicy.getStalenessSecs(entry, now) > 0L) {
cachedResponse.addHeader(HeaderConstants.WARNING,"110 localhost \"Response is stale\"");
}
return cachedResponse;
}
代码示例来源:origin: org.apache.httpcomponents.client5/httpclient5-cache
private boolean hasSupportedEtagValidator(final HttpRequest request) {
return request.containsHeader(HeaderConstants.IF_NONE_MATCH);
}
代码示例来源:origin: org.apache.httpcomponents.core5/httpcore5
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
if (!request.containsHeader(HttpHeaders.USER_AGENT) && this.userAgent != null) {
request.addHeader(HttpHeaders.USER_AGENT, this.userAgent);
}
}
代码示例来源:origin: apache/httpcomponents-core
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
if (!request.containsHeader(HttpHeaders.USER_AGENT) && this.userAgent != null) {
request.addHeader(HttpHeaders.USER_AGENT, this.userAgent);
}
}
代码示例来源:origin: apache/httpcomponents-core
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
final String method = request.getMethod();
if (method.equalsIgnoreCase("CONNECT")) {
return;
}
if (!request.containsHeader(HttpHeaders.CONNECTION)) {
// Default policy is to keep connection alive
// whenever possible
if (request.containsHeader(HttpHeaders.UPGRADE)) {
request.addHeader(HttpHeaders.CONNECTION, HeaderElements.UPGRADE);
} else {
request.addHeader(HttpHeaders.CONNECTION, HeaderElements.KEEP_ALIVE);
}
}
}
代码示例来源:origin: org.apache.httpcomponents.core5/httpcore5
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
final String method = request.getMethod();
if (method.equalsIgnoreCase("CONNECT")) {
return;
}
if (!request.containsHeader(HttpHeaders.CONNECTION)) {
// Default policy is to keep connection alive
// whenever possible
if (request.containsHeader(HttpHeaders.UPGRADE)) {
request.addHeader(HttpHeaders.CONNECTION, HeaderElements.UPGRADE);
} else {
request.addHeader(HttpHeaders.CONNECTION, HeaderElements.KEEP_ALIVE);
}
}
}
代码示例来源:origin: org.apache.httpcomponents.core5/httpcore5
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
if (entity != null && !request.containsHeader(HttpHeaders.DATE)) {
request.setHeader(HttpHeaders.DATE, HttpDateGenerator.INSTANCE.getCurrentDate());
}
}
代码示例来源:origin: apache/httpcomponents-core
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
if (entity != null && !request.containsHeader(HttpHeaders.DATE)) {
request.setHeader(HttpHeaders.DATE, HttpDateGenerator.INSTANCE.getCurrentDate());
}
}
代码示例来源:origin: org.apache.httpcomponents.client5/httpclient5-cache
SimpleHttpResponse generateCachedResponse(
final HttpRequest request,
final HttpContext context,
final HttpCacheEntry entry,
final Date now) throws ResourceIOException {
final SimpleHttpResponse cachedResponse;
if (request.containsHeader(HeaderConstants.IF_NONE_MATCH)
|| request.containsHeader(HeaderConstants.IF_MODIFIED_SINCE)) {
cachedResponse = responseGenerator.generateNotModifiedResponse(entry);
} else {
cachedResponse = responseGenerator.generateResponse(request, entry);
}
setResponseStatus(context, CacheResponseStatus.CACHE_HIT);
if (validityPolicy.getStalenessSecs(entry, now) > 0L) {
cachedResponse.addHeader(HeaderConstants.WARNING,"110 localhost \"Response is stale\"");
}
return cachedResponse;
}
代码示例来源:origin: org.apache.httpcomponents.client5/httpclient5
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
final String method = request.getMethod();
if (method.equalsIgnoreCase("CONNECT")) {
return;
}
if (this.defaultHeaders != null) {
for (final Header defHeader : this.defaultHeaders) {
if(!request.containsHeader(defHeader.getName())) {
request.addHeader(defHeader);
}
}
}
}
代码示例来源:origin: apache/httpcomponents-core
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
if (!request.containsHeader(HttpHeaders.EXPECT)) {
if (entity != null) {
final ProtocolVersion ver = context.getProtocolVersion();
// Do not send the expect header if request body is known to be empty
if (entity.getContentLength() != 0 && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
request.addHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE);
}
}
}
}
代码示例来源:origin: org.apache.httpcomponents.core5/httpcore5
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
if (!request.containsHeader(HttpHeaders.EXPECT)) {
if (entity != null) {
final ProtocolVersion ver = context.getProtocolVersion();
// Do not send the expect header if request body is known to be empty
if (entity.getContentLength() != 0 && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
request.addHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE);
}
}
}
}
代码示例来源:origin: org.apache.httpcomponents.client5/httpclient5
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
final String method = request.getMethod();
if (method.equalsIgnoreCase("CONNECT")) {
request.setHeader(PROXY_CONN_DIRECTIVE, HeaderElements.KEEP_ALIVE);
return;
}
final HttpClientContext clientContext = HttpClientContext.adapt(context);
// Obtain the client connection (required)
final RouteInfo route = clientContext.getHttpRoute();
if (route == null) {
this.log.debug("Connection route not set in the context");
return;
}
if (route.getHopCount() == 1 || route.isTunnelled()) {
if (!request.containsHeader(HttpHeaders.CONNECTION)) {
request.addHeader(HttpHeaders.CONNECTION, HeaderElements.KEEP_ALIVE);
}
}
if (route.getHopCount() == 2 && !route.isTunnelled()) {
if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) {
request.addHeader(PROXY_CONN_DIRECTIVE, HeaderElements.KEEP_ALIVE);
}
}
}
代码示例来源:origin: org.apache.httpcomponents.client5/httpclient5
httpProcessor.process(request, entityProducer, clientContext);
if (!request.containsHeader(HttpHeaders.AUTHORIZATION)) {
if (log.isDebugEnabled()) {
log.debug("Target auth state: " + targetAuthExchange.getState());
if (!request.containsHeader(HttpHeaders.PROXY_AUTHORIZATION) && !route.isTunnelled()) {
if (log.isDebugEnabled()) {
log.debug("Proxy auth state: " + proxyAuthExchange.getState());
代码示例来源:origin: apache/httpcomponents-core
request.removeHeaders(HttpHeaders.CONTENT_LENGTH);
} else {
if (request.containsHeader(HttpHeaders.TRANSFER_ENCODING)) {
throw new ProtocolException("Transfer-encoding header already present");
if (request.containsHeader(HttpHeaders.CONTENT_LENGTH)) {
throw new ProtocolException("Content-Length header already present");
代码示例来源:origin: org.apache.httpcomponents.core5/httpcore5
request.removeHeaders(HttpHeaders.CONTENT_LENGTH);
} else {
if (request.containsHeader(HttpHeaders.TRANSFER_ENCODING)) {
throw new ProtocolException("Transfer-encoding header already present");
if (request.containsHeader(HttpHeaders.CONTENT_LENGTH)) {
throw new ProtocolException("Content-Length header already present");
代码示例来源:origin: org.apache.httpcomponents.client5/httpclient5
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
if (!request.containsHeader(HttpHeaders.EXPECT)) {
final ProtocolVersion version = request.getVersion() != null ? request.getVersion() : HttpVersion.HTTP_1_1;
// Do not send the expect header if request body is known to be empty
if (entity != null
&& entity.getContentLength() != 0 && !version.lessEquals(HttpVersion.HTTP_1_0)) {
final HttpClientContext clientContext = HttpClientContext.adapt(context);
final RequestConfig config = clientContext.getRequestConfig();
if (config.isExpectContinueEnabled()) {
request.addHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE);
}
}
}
}
代码示例来源:origin: org.apache.httpcomponents.core5/httpcore5
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
Args.notNull(context, "HTTP context");
final ProtocolVersion ver = context.getProtocolVersion();
final String method = request.getMethod();
if (method.equalsIgnoreCase("CONNECT") && ver.lessEquals(HttpVersion.HTTP_1_0)) {
return;
}
if (!request.containsHeader(HttpHeaders.HOST)) {
URIAuthority authority = request.getAuthority();
if (authority == null) {
if (ver.lessEquals(HttpVersion.HTTP_1_0)) {
return;
}
throw new ProtocolException("Target host is unknown");
}
if (authority.getUserInfo() != null) {
authority = new URIAuthority(authority.getHostName(), authority.getPort());
}
request.addHeader(HttpHeaders.HOST, authority);
}
}
代码示例来源:origin: apache/httpcomponents-core
@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
Args.notNull(context, "HTTP context");
final ProtocolVersion ver = context.getProtocolVersion();
final String method = request.getMethod();
if (method.equalsIgnoreCase("CONNECT") && ver.lessEquals(HttpVersion.HTTP_1_0)) {
return;
}
if (!request.containsHeader(HttpHeaders.HOST)) {
URIAuthority authority = request.getAuthority();
if (authority == null) {
if (ver.lessEquals(HttpVersion.HTTP_1_0)) {
return;
}
throw new ProtocolException("Target host is unknown");
}
if (authority.getUserInfo() != null) {
authority = new URIAuthority(authority.getHostName(), authority.getPort());
}
request.addHeader(HttpHeaders.HOST, authority);
}
}
内容来源于网络,如有侵权,请联系作者删除!