Java Code Examples for org.apache.http.HttpRequest#containsHeader()
The following examples show how to use
org.apache.http.HttpRequest#containsHeader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AwsSigner4.java From jkube with Eclipse Public License 2.0 | 5 votes |
/** * 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); } }
Example 2
Source File: LoggingHttpRequestExecutor.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public HttpResponse execute(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException { if(!request.containsHeader(HttpHeaders.USER_AGENT)) { request.addHeader(new BasicHeader(HttpHeaders.USER_AGENT, useragentProvider.get())); } return super.execute(request, conn, context); }
Example 3
Source File: HttpClientUtil.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding", "gzip, deflate"); } }
Example 4
Source File: AwsSigner4.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 5
Source File: HeaderManager.java From esigate with Apache License 2.0 | 5 votes |
/** * Copy header from originalRequest to httpRequest. * <p> * Referer is rewritten. X-Forwarded-* headers are updated. * * @param originalRequest * source request * @param httpRequest * destination request */ public void copyHeaders(DriverRequest originalRequest, HttpRequest httpRequest) { String baseUrl = originalRequest.getBaseUrl().toString(); String visibleBaseUrl = originalRequest.getVisibleBaseUrl(); for (Header header : originalRequest.getOriginalRequest().getAllHeaders()) { String name = header.getName(); // Special headers if (HttpHeaders.REFERER.equalsIgnoreCase(name) && isForwardedRequestHeader(HttpHeaders.REFERER)) { String value = header.getValue(); value = urlRewriter.rewriteReferer(value, baseUrl, visibleBaseUrl); httpRequest.addHeader(name, value); // All other headers are copied if allowed } else if (isForwardedRequestHeader(name)) { httpRequest.addHeader(header); } } // process X-Forwarded-For header String remoteAddr = originalRequest.getOriginalRequest().getRemoteAddr(); if (remoteAddr != null) { String forwardedFor = null; if (httpRequest.containsHeader("X-Forwarded-For")) { forwardedFor = httpRequest.getFirstHeader("X-Forwarded-For").getValue(); } if (forwardedFor == null) { forwardedFor = remoteAddr; } else { forwardedFor = forwardedFor + ", " + remoteAddr; } httpRequest.setHeader("X-Forwarded-For", forwardedFor); } // Process X-Forwarded-Proto header if (!httpRequest.containsHeader("X-Forwarded-Proto")) { httpRequest.addHeader("X-Forwarded-Proto", UriUtils.extractScheme(originalRequest.getOriginalRequest().getRequestLine().getUri())); } }
Example 6
Source File: GzipRequestInterceptor.java From fanfouapp-opensource with Apache License 2.0 | 5 votes |
@Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (!request .containsHeader(GzipRequestInterceptor.HEADER_ACCEPT_ENCODING)) { request.addHeader(GzipRequestInterceptor.HEADER_ACCEPT_ENCODING, GzipRequestInterceptor.ENCODING_GZIP); } }
Example 7
Source File: HttpClientGrayHeaderCustomizer.java From summerframework with Apache License 2.0 | 4 votes |
@Override protected boolean containsKey(HttpRequest request, String key) { return request.containsHeader(key); }
Example 8
Source File: GzipRequestInterceptor.java From YiBo with Apache License 2.0 | 4 votes |
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding", "gzip"); } }
Example 9
Source File: CachedResponseSuitabilityChecker.java From apigee-android-sdk with Apache License 2.0 | 4 votes |
private boolean hasSupportedEtagVadlidator(HttpRequest request) { return request.containsHeader(HeaderConstants.IF_NONE_MATCH); }