本文整理了Java中org.apache.http.HttpRequest.containsHeader()
方法的一些代码示例,展示了HttpRequest.containsHeader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.containsHeader()
方法的具体详情如下:
包路径:org.apache.http.HttpRequest
类名称:HttpRequest
方法名:containsHeader
暂无
代码示例来源:origin: code4craft/webmagic
public void process(
final HttpRequest request,
final HttpContext context) throws HttpException, IOException {
if (!request.containsHeader("Accept-Encoding")) {
request.addHeader("Accept-Encoding", "gzip");
}
}
});
代码示例来源:origin: mttkay/ignition
@Override
public void process(final HttpRequest request, final HttpContext context) {
// Add header to accept gzip content
if (!request.containsHeader(IgnitedHttp.HEADER_ACCEPT_ENCODING)) {
request.addHeader(IgnitedHttp.HEADER_ACCEPT_ENCODING, IgnitedHttp.ENCODING_GZIP);
}
}
代码示例来源:origin: robovm/robovm
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
// Default policy is to keep connection alive
// whenever possible
request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
}
}
代码示例来源:origin: robovm/robovm
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException
("HTTP request may not be null.");
}
if ((request instanceof HttpEntityEnclosingRequest) &&
!request.containsHeader(HTTP.DATE_HEADER)) {
String httpdate = DATE_GENERATOR.getCurrentDate();
request.setHeader(HTTP.DATE_HEADER, httpdate);
}
}
代码示例来源:origin: rest-assured/rest-assured
public void process( final HttpRequest req,
final HttpContext context ) throws HttpException, IOException {
// set the Accept-Encoding header:
String encoding = getContentEncoding();
if ( !req.containsHeader( ACCEPT_ENC_HDR ) )
req.addHeader( ACCEPT_ENC_HDR, encoding );
else {
StringBuilder values = new StringBuilder();
for ( Header h : req.getHeaders( ACCEPT_ENC_HDR ) )
values.append( h.getValue() ).append( "," );
String encList = (!values.toString().contains( encoding )) ? values
.append( encoding ).toString()
: values.toString().substring( 0, values.lastIndexOf( "," ) );
req.setHeader( ACCEPT_ENC_HDR, encList );
}
//TODO compress request and add content-encoding header.
}
}
代码示例来源:origin: robovm/robovm
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (!request.containsHeader(HTTP.USER_AGENT)) {
String useragent = HttpProtocolParams.getUserAgent(request.getParams());
if (useragent != null) {
request.addHeader(HTTP.USER_AGENT, useragent);
}
}
}
代码示例来源:origin: robovm/robovm
throw new IllegalArgumentException("HTTP context may not be null");
if (!request.containsHeader(HTTP.TARGET_HOST)) {
HttpHost targethost = (HttpHost) context
.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
代码示例来源:origin: robovm/robovm
if (request.containsHeader(HTTP.TRANSFER_ENCODING)) {
throw new ProtocolException("Transfer-encoding header already present");
if (request.containsHeader(HTTP.CONTENT_LEN)) {
throw new ProtocolException("Content-Length header already present");
if (entity.getContentType() != null && !request.containsHeader(
HTTP.CONTENT_TYPE )) {
request.addHeader(entity.getContentType());
if (entity.getContentEncoding() != null && !request.containsHeader(
HTTP.CONTENT_ENCODING)) {
request.addHeader(entity.getContentEncoding());
代码示例来源:origin: robovm/robovm
if (request.containsHeader(AUTH.PROXY_AUTH_RESP)) {
return;
代码示例来源:origin: robovm/robovm
if (request.containsHeader(AUTH.WWW_AUTH_RESP)) {
return;
代码示例来源:origin: fabric8io/docker-maven-plugin
/**
* Sign a request. Add the headers that authenticate the request.
*
* @param request The request to sign.
* @param credentials The credentials to use when signing.
* @param signingTime The invocation time to use;
*/
void sign(HttpRequest request, AuthConfig credentials, Date signingTime) {
AwsSigner4Request sr = new AwsSigner4Request(region, service, request, signingTime);
if(!request.containsHeader("X-Amz-Date")) {
request.addHeader("X-Amz-Date", sr.getSigningDateTime());
}
request.addHeader("Authorization", task4(sr, credentials));
final String securityToken = credentials.getAuth();
if (StringUtils.isNotEmpty(securityToken)) {
request.addHeader("X-Amz-Security-Token", securityToken);
}
}
代码示例来源:origin: stackoverflow.com
httpclient.addRequestInterceptor(new HttpRequestInterceptor() {
public void process(
final HttpRequest request,
final HttpContext context) throws HttpException, IOException {
if (!request.containsHeader("Accept-Encoding")) {
request.addHeader("Accept-Encoding", "gzip");
}
}
});
代码示例来源:origin: com.jayway.restassured/rest-assured
public void process( final HttpRequest req,
final HttpContext context ) throws HttpException, IOException {
// set the Accept-Encoding header:
String encoding = getContentEncoding();
if ( !req.containsHeader( ACCEPT_ENC_HDR ) )
req.addHeader( ACCEPT_ENC_HDR, encoding );
else {
StringBuilder values = new StringBuilder();
for ( Header h : req.getHeaders( ACCEPT_ENC_HDR ) )
values.append( h.getValue() ).append( "," );
String encList = (!values.toString().contains( encoding )) ? values
.append( encoding ).toString()
: values.toString().substring( 0, values.lastIndexOf( "," ) );
req.setHeader( ACCEPT_ENC_HDR, encList );
}
//TODO compress request and add content-encoding header.
}
}
代码示例来源:origin: stackoverflow.com
IOException {
for (String key : sendHeaders.keySet()) {
if (!request.containsHeader(key)) {
request.addHeader(key, sendHeaders.get(key));
代码示例来源:origin: stackoverflow.com
private static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding";
private static final String ENCODING_GZIP = "gzip";
final DefaultHttpClient client = new DefaultHttpClient(manager, parameters);
client.addRequestInterceptor(new HttpRequestInterceptor() {
public void process(HttpRequest request, HttpContext context) {
// Add header to accept gzip content
if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
}
}
});
client.addResponseInterceptor(new HttpResponseInterceptor() {
public void process(HttpResponse response, HttpContext context) {
// Inflate any responses compressed with gzip
final HttpEntity entity = response.getEntity();
final Header encoding = entity.getContentEncoding();
if (encoding != null) {
for (HeaderElement element : encoding.getElements()) {
if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
response.setEntity(new InflatingEntity(response.getEntity()));
break;
}
}
}
}
});
代码示例来源:origin: org.apache.solr/solr-solrj
@Override
public void process(HttpRequest request, HttpContext context)
throws HttpException, IOException {
if (!request.containsHeader("Accept-Encoding")) {
request.addHeader("Accept-Encoding", "gzip, deflate");
}
}
}
代码示例来源:origin: MobiVM/robovm
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
// Default policy is to keep connection alive
// whenever possible
request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
}
}
代码示例来源:origin: MobiVM/robovm
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (!request.containsHeader(HTTP.USER_AGENT)) {
String useragent = HttpProtocolParams.getUserAgent(request.getParams());
if (useragent != null) {
request.addHeader(HTTP.USER_AGENT, useragent);
}
}
}
代码示例来源:origin: ibinti/bugvm
@Override
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
if ((request instanceof HttpEntityEnclosingRequest) &&
!request.containsHeader(HTTP.DATE_HEADER)) {
final String httpdate = DATE_GENERATOR.getCurrentDate();
request.setHeader(HTTP.DATE_HEADER, httpdate);
}
}
代码示例来源:origin: com.bugvm/bugvm-rt
@Override
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
if ((request instanceof HttpEntityEnclosingRequest) &&
!request.containsHeader(HTTP.DATE_HEADER)) {
final String httpdate = DATE_GENERATOR.getCurrentDate();
request.setHeader(HTTP.DATE_HEADER, httpdate);
}
}
内容来源于网络,如有侵权,请联系作者删除!