List of usage examples for org.apache.http.protocol HTTP DATE_HEADER
String DATE_HEADER
To view the source code for org.apache.http.protocol HTTP DATE_HEADER.
Click Source Link
From source file:com.messagemedia.restapi.client.v1.internal.http.interceptors.RequestDateInterceptor.java
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { Args.notNull(request, "HTTP request"); if (!request.containsHeader(HTTP.DATE_HEADER)) { final String httpdate = DATE_GENERATOR.getCurrentDate(); request.setHeader(HTTP.DATE_HEADER, httpdate); }/*w ww . j a v a 2 s. co m*/ }
From source file:com.messagemedia.restapi.client.v1.internal.http.interceptors.HmacMmv2InterceptorTest.java
@Before public void setUp() throws IllegalStateException, IOException { this.interceptor = new HmacMmv2Interceptor(API_KEY, SECRET_KEY); request = Mockito.mock(HttpEntityEnclosingRequest.class); Mockito.when(request.getFirstHeader(HTTP.DATE_HEADER)).thenReturn(new BasicHeader("", DATE_HEADER)); Mockito.when(request.getRequestLine()) .thenReturn(new BasicRequestLine("POST", "/v1/messages", HttpVersion.HTTP_1_1)); }
From source file:com.apigee.sdk.apm.http.impl.client.cache.CacheValidityPolicy.java
protected Date getDateValue(final HttpCacheEntry entry) { Header dateHdr = entry.getFirstHeader(HTTP.DATE_HEADER); if (dateHdr == null) return null; try {// w ww. j a v a 2 s . c o m return DateUtils.parseDate(dateHdr.getValue()); } catch (DateParseException dpe) { // ignore malformed date } return null; }
From source file:com.apigee.sdk.apm.http.impl.client.cache.ResponseCachingPolicy.java
/** * Determines if an HttpResponse can be cached. * /*w w w . j a va2s .c om*/ * @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(String httpMethod, HttpResponse response) { boolean cacheable = false; if (!HeaderConstants.GET_METHOD.equals(httpMethod)) { log.debug("Response was not cacheable."); return false; } switch (response.getStatusLine().getStatusCode()) { case HttpStatus.SC_OK: case HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION: case HttpStatus.SC_MULTIPLE_CHOICES: case HttpStatus.SC_MOVED_PERMANENTLY: case HttpStatus.SC_GONE: // these response codes MAY be cached cacheable = true; log.debug("Response was cacheable"); break; case HttpStatus.SC_PARTIAL_CONTENT: // we don't implement Range requests and hence are not // allowed to cache partial content log.debug("Response was not cacheable (Partial Content)"); return cacheable; default: // If the status code is not one of the recognized // available codes in HttpStatus Don't Cache log.debug("Response was not cacheable (Unknown Status code)"); return cacheable; } Header contentLength = response.getFirstHeader(HTTP.CONTENT_LEN); if (contentLength != null) { int contentLengthValue = Integer.parseInt(contentLength.getValue()); if (contentLengthValue > this.maxObjectSizeBytes) return false; } Header[] ageHeaders = response.getHeaders(HeaderConstants.AGE); if (ageHeaders.length > 1) return false; Header[] expiresHeaders = response.getHeaders(HeaderConstants.EXPIRES); if (expiresHeaders.length > 1) return false; Header[] dateHeaders = response.getHeaders(HTTP.DATE_HEADER); if (dateHeaders.length != 1) return false; try { DateUtils.parseDate(dateHeaders[0].getValue()); } catch (DateParseException dpe) { return false; } for (Header varyHdr : response.getHeaders(HeaderConstants.VARY)) { for (HeaderElement elem : varyHdr.getElements()) { if ("*".equals(elem.getName())) { return false; } } } if (isExplicitlyNonCacheable(response)) return false; return (cacheable || isExplicitlyCacheable(response)); }
From source file:com.apigee.sdk.apm.http.impl.client.cache.CacheEntryUpdater.java
private boolean entryDateHeaderNewerThenResponse(HttpCacheEntry entry, HttpResponse response) { try {/* w ww .j ava2s.co m*/ Date entryDate = DateUtils.parseDate(entry.getFirstHeader(HTTP.DATE_HEADER).getValue()); Date responseDate = DateUtils.parseDate(response.getFirstHeader(HTTP.DATE_HEADER).getValue()); if (!entryDate.after(responseDate)) { return false; } } catch (DateParseException e) { return false; } return true; }
From source file:com.apigee.sdk.apm.http.impl.client.cache.CacheEntryUpdater.java
private boolean entryAndResponseHaveDateHeader(HttpCacheEntry entry, HttpResponse response) { if (entry.getFirstHeader(HTTP.DATE_HEADER) != null && response.getFirstHeader(HTTP.DATE_HEADER) != null) { return true; }//from ww w.j a v a 2 s . c o m return false; }
From source file:com.apigee.sdk.apm.http.impl.client.cache.ResponseProtocolCompliance.java
private void ensure206ContainsDateHeader(HttpResponse response) { if (response.getFirstHeader(HTTP.DATE_HEADER) == null) { response.addHeader(HTTP.DATE_HEADER, DateUtils.formatDate(new Date())); }//from w w w.jav a2 s . co m }
From source file:org.apache.synapse.transport.nhttp.HttpCoreNIOSender.java
/** * Remove unwanted headers from the given header map. * * @param headers Header map//from ww w.j a va 2 s . c o m * @param nHttpConfiguration NHttp transporter base configurations */ private void removeUnwantedHeadersFromHeaderMap(Map headers, NHttpConfiguration nHttpConfiguration) { Iterator iter = headers.keySet().iterator(); while (iter.hasNext()) { String headerName = (String) iter.next(); if (HTTP.CONN_DIRECTIVE.equalsIgnoreCase(headerName) || HTTP.TRANSFER_ENCODING.equalsIgnoreCase(headerName) || HTTP.CONTENT_TYPE.equalsIgnoreCase(headerName) || HTTP.CONTENT_LEN.equalsIgnoreCase(headerName)) { iter.remove(); } if (HTTP.SERVER_HEADER.equalsIgnoreCase(headerName) && !nHttpConfiguration.isPreserveHttpHeader(HTTP.SERVER_HEADER)) { iter.remove(); } if (HTTP.USER_AGENT.equalsIgnoreCase(headerName) && !nHttpConfiguration.isPreserveHttpHeader(HTTP.USER_AGENT)) { iter.remove(); } if (HTTP.DATE_HEADER.equalsIgnoreCase(headerName) && !nHttpConfiguration.isPreserveHttpHeader(HTTP.DATE_HEADER)) { iter.remove(); } } }