List of usage examples for io.netty.handler.codec.http HttpHeaders getDateHeader
@Deprecated public static Date getDateHeader(HttpMessage message, CharSequence name) throws ParseException
From source file:com.barchart.netty.server.http.handlers.StaticResourceHandler.java
License:BSD License
private boolean handleCache(final HttpServerRequest request, final Resource resource) { // Cache-Control: no-cache if (request.headers().contains(HttpHeaders.Names.CACHE_CONTROL) && request.headers().get(HttpHeaders.Names.CACHE_CONTROL).equals(HttpHeaders.Values.NO_CACHE)) { return false; }/*from w ww . j av a 2 s. c om*/ // If-Modified-Since: <date> if (request.headers().contains(HttpHeaders.Names.IF_MODIFIED_SINCE)) { try { final Date cached = HttpHeaders.getDateHeader(request, HttpHeaders.Names.IF_MODIFIED_SINCE); if (cached.getTime() >= resource.modified()) { // Cache is good, return 304 request.response().setStatus(HttpResponseStatus.NOT_MODIFIED); request.response().setContentLength(0); return true; } } catch (final ParseException e) { // Bad date header } } // Send resource return false; }
From source file:com.github.ambry.rest.NettyResponseChannelTest.java
License:Open Source License
/** * Checks the headers in the response match those in the request. * @param request the {@link HttpRequest} with the original value of the headers. * @param response the {@link HttpResponse} that should have the same value for some headers in {@code request}. * @throws ParseException//from w w w .jav a 2 s.c om */ private void checkHeaders(HttpRequest request, HttpResponse response) throws ParseException { assertEquals("Unexpected response status", HttpResponseStatus.ACCEPTED, response.getStatus()); assertEquals(HttpHeaders.Names.CONTENT_TYPE + " does not match", HttpHeaders.getHeader(request, HttpHeaders.Names.CONTENT_TYPE), HttpHeaders.getHeader(response, HttpHeaders.Names.CONTENT_TYPE)); assertEquals(HttpHeaders.Names.CONTENT_LENGTH + " does not match", HttpHeaders.getHeader(request, HttpHeaders.Names.CONTENT_LENGTH), HttpHeaders.getHeader(response, HttpHeaders.Names.CONTENT_LENGTH)); assertEquals(HttpHeaders.Names.LOCATION + " does not match", HttpHeaders.getHeader(request, HttpHeaders.Names.LOCATION), HttpHeaders.getHeader(response, HttpHeaders.Names.LOCATION)); assertEquals(HttpHeaders.Names.LAST_MODIFIED + " does not match", HttpHeaders.getDateHeader(request, HttpHeaders.Names.LAST_MODIFIED), HttpHeaders.getDateHeader(response, HttpHeaders.Names.LAST_MODIFIED)); assertEquals(HttpHeaders.Names.EXPIRES + " does not match", HttpHeaders.getDateHeader(request, HttpHeaders.Names.EXPIRES), HttpHeaders.getDateHeader(response, HttpHeaders.Names.EXPIRES)); assertEquals(HttpHeaders.Names.CACHE_CONTROL + " does not match", HttpHeaders.getHeader(request, HttpHeaders.Names.CACHE_CONTROL), HttpHeaders.getHeader(response, HttpHeaders.Names.CACHE_CONTROL)); assertEquals(HttpHeaders.Names.PRAGMA + " does not match", HttpHeaders.getHeader(request, HttpHeaders.Names.PRAGMA), HttpHeaders.getHeader(response, HttpHeaders.Names.PRAGMA)); assertEquals(HttpHeaders.Names.DATE + " does not match", HttpHeaders.getDateHeader(request, HttpHeaders.Names.DATE), HttpHeaders.getDateHeader(response, HttpHeaders.Names.DATE)); assertEquals(MockNettyMessageProcessor.CUSTOM_HEADER_NAME + " does not match", HttpHeaders.getHeader(request, MockNettyMessageProcessor.CUSTOM_HEADER_NAME), HttpHeaders.getHeader(response, MockNettyMessageProcessor.CUSTOM_HEADER_NAME)); }
From source file:com.github.ambry.rest.NettyResponseChannelTest.java
License:Open Source License
/** * Copies headers from request to response. * @param httpRequest the {@link HttpRequest} to copy headers from. * @throws ParseException// w ww . j av a 2 s . co m * @throws RestServiceException */ private void copyHeaders(HttpRequest httpRequest) throws ParseException, RestServiceException { restResponseChannel.setStatus(ResponseStatus.Accepted); restResponseChannel.setHeader(RestUtils.Headers.CONTENT_TYPE, HttpHeaders.getHeader(httpRequest, HttpHeaders.Names.CONTENT_TYPE)); restResponseChannel.setHeader(RestUtils.Headers.CONTENT_LENGTH, Long.parseLong(HttpHeaders.getHeader(httpRequest, HttpHeaders.Names.CONTENT_LENGTH))); restResponseChannel.setHeader(RestUtils.Headers.LOCATION, HttpHeaders.getHeader(httpRequest, HttpHeaders.Names.LOCATION)); restResponseChannel.setHeader(RestUtils.Headers.LAST_MODIFIED, HttpHeaders.getDateHeader(httpRequest, HttpHeaders.Names.LAST_MODIFIED)); restResponseChannel.setHeader(RestUtils.Headers.EXPIRES, HttpHeaders.getDateHeader(httpRequest, HttpHeaders.Names.EXPIRES)); restResponseChannel.setHeader(RestUtils.Headers.CACHE_CONTROL, HttpHeaders.getHeader(httpRequest, HttpHeaders.Names.CACHE_CONTROL)); restResponseChannel.setHeader(RestUtils.Headers.PRAGMA, HttpHeaders.getHeader(httpRequest, HttpHeaders.Names.PRAGMA)); restResponseChannel.setHeader(RestUtils.Headers.DATE, HttpHeaders.getDateHeader(httpRequest, HttpHeaders.Names.DATE)); restResponseChannel.setHeader(CUSTOM_HEADER_NAME, HttpHeaders.getHeader(httpRequest, CUSTOM_HEADER_NAME)); }
From source file:io.reactivex.netty.protocol.http.client.HttpRequestHeaders.java
License:Apache License
public Date getDateHeader(CharSequence name) throws ParseException { return HttpHeaders.getDateHeader(nettyRequest, name); }
From source file:io.reactivex.netty.protocol.http.client.HttpRequestHeaders.java
License:Apache License
public Date getDateHeader(String name) throws ParseException { return HttpHeaders.getDateHeader(nettyRequest, name); }
From source file:io.reactivex.netty.protocol.http.client.HttpResponseHeaders.java
License:Apache License
public Date getDateHeader(CharSequence name) throws ParseException { return HttpHeaders.getDateHeader(nettyResponse, name); }
From source file:io.reactivex.netty.protocol.http.client.HttpResponseHeaders.java
License:Apache License
public Date getDateHeader(String name) throws ParseException { return HttpHeaders.getDateHeader(nettyResponse, name); }
From source file:org.nosceon.titanite.HeaderParams.java
License:Apache License
public Date getDate(String name) { return Optional.ofNullable(HttpHeaders.getHeader(message, name)).flatMap((o) -> { try {/* w w w . ja v a2 s . co m*/ return Optional.of(HttpHeaders.getDateHeader(message, name)); } catch (ParseException e) { return Optional.empty(); } }).orElse(null); }
From source file:reactor.io.net.impl.netty.http.NettyHttpResponseHeaders.java
License:Open Source License
@Override public Date getDateHeader(String name) throws ParseException { return HttpHeaders.getDateHeader(this.nettyResponse, name); }
From source file:rxweb.engine.server.netty.NettyRequestHeadersAdapter.java
License:Apache License
@Override public Date getDateHeader(String name) throws ParseException { return HttpHeaders.getDateHeader(this.nettyRequest, name); }