List of usage examples for io.netty.handler.codec.http HttpHeaderNames LAST_MODIFIED
AsciiString LAST_MODIFIED
To view the source code for io.netty.handler.codec.http HttpHeaderNames LAST_MODIFIED.
Click Source Link
From source file:com.cmz.http.file.HttpStaticFileServerHandler.java
License:Apache License
/** * Sets the Date and Cache headers for the HTTP Response * * @param response/* w w w .j a va 2 s . c o m*/ * HTTP response * @param fileToCache * file to extract content type */ private static void setDateAndCacheHeaders(HttpResponse response, File fileToCache) { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE)); // Date header Calendar time = new GregorianCalendar(); response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(time.getTime())); // Add cache headers time.add(Calendar.SECOND, HTTP_CACHE_SECONDS); response.headers().set(HttpHeaderNames.EXPIRES, dateFormatter.format(time.getTime())); response.headers().set(HttpHeaderNames.CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS); response.headers().set(HttpHeaderNames.LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified()))); }
From source file:com.linecorp.armeria.server.http.file.HttpFileServiceInvocationHandler.java
License:Apache License
private static void respond(ServiceInvocationContext ctx, Promise<Object> promise, HttpResponseStatus status, long lastModifiedMillis, String contentType, ByteBuf content) { final FullHttpResponse res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, content); if (lastModifiedMillis != 0) { res.headers().set(HttpHeaderNames.LAST_MODIFIED, new Date(lastModifiedMillis)); }//from w w w .j a v a 2s .co m if (contentType != null) { res.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType); } ctx.resolvePromise(promise, res); }
From source file:com.ociweb.pronghorn.adapter.netty.impl.HttpStaticFileServerHandler.java
License:Apache License
/** * Sets the Date and Cache headers for the HTTP Response * * @param response//from w w w . ja va2 s .c om * HTTP response * @param fileToCache * file to extract content type */ private static void setDateAndCacheHeaders(HttpResponse response, long lastModified) { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE)); // Date header Calendar time = new GregorianCalendar(); response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(time.getTime())); // Add cache headers time.add(Calendar.SECOND, HTTP_CACHE_SECONDS); response.headers().set(HttpHeaderNames.EXPIRES, dateFormatter.format(time.getTime())); response.headers().set(HttpHeaderNames.CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS); response.headers().set(HttpHeaderNames.LAST_MODIFIED, dateFormatter.format(new Date(lastModified))); }
From source file:dpfmanager.shell.modules.server.get.HttpGetHandler.java
License:Open Source License
private void setDateAndCacheHeaders(HttpResponse response, File fileToCache) { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE)); // Date header Calendar time = new GregorianCalendar(); response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(time.getTime())); // Add cache headers time.add(Calendar.SECOND, HTTP_CACHE_SECONDS); response.headers().set(HttpHeaderNames.EXPIRES, dateFormatter.format(time.getTime())); response.headers().set(HttpHeaderNames.CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS); response.headers().set(HttpHeaderNames.LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified()))); }
From source file:fr.kissy.zergling_push.infrastructure.HttpStaticFileServerHandler.java
License:Apache License
/** * Sets the Date and Cache headers for the HTTP Response * * @param response/*from ww w . j av a2 s . c o m*/ * HTTP response * @param fileToCache * file to extract content type */ private static void setDateAndCacheHeaders(HttpResponse response, File fileToCache) { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE)); // Date header Calendar time = new GregorianCalendar(); response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(time.getTime())); // Add cache headers response.headers().set(HttpHeaderNames.EXPIRES, dateFormatter.format(time.getTime())); response.headers().set(HttpHeaderNames.CACHE_CONTROL, "no-store"); response.headers().set(HttpHeaderNames.LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified()))); }
From source file:org.cloudfoundry.dependency.resource.http.HttpCheckAction.java
License:Apache License
private Mono<Instant> requestLastModified() { return this.httpClient.request(HttpMethod.HEAD, getUri(), request -> request).flatMap( response -> Mono.just(response.responseHeaders().getTimeMillis(HttpHeaderNames.LAST_MODIFIED))) .map(Instant::ofEpochMilli); }
From source file:org.glowroot.ui.CommonHandler.java
License:Apache License
private CommonResponse handleStaticResource(String path, CommonRequest request) throws IOException { URL url = getSecureUrlForPath(RESOURCE_BASE + path); if (url == null) { // log at debug only since this is typically just exploit bot spam logger.debug("unexpected path: {}", path); return new CommonResponse(NOT_FOUND); }/*from w ww.j a va 2s . c om*/ Date expires = getExpiresForPath(path); if (request.getHeader(HttpHeaderNames.IF_MODIFIED_SINCE) != null && expires == null) { // all static resources without explicit expires are versioned and can be safely // cached forever return new CommonResponse(NOT_MODIFIED); } int extensionStartIndex = path.lastIndexOf('.'); checkState(extensionStartIndex != -1, "found path under %s with no extension: %s", RESOURCE_BASE, path); String extension = path.substring(extensionStartIndex + 1); MediaType mediaType = mediaTypes.get(extension); checkNotNull(mediaType, "found extension under %s with no media type: %s", RESOURCE_BASE, extension); CommonResponse response = new CommonResponse(OK, mediaType, url); if (expires != null) { response.setHeader(HttpHeaderNames.EXPIRES, expires); } else { response.setHeader(HttpHeaderNames.LAST_MODIFIED, new Date(0)); response.setHeader(HttpHeaderNames.EXPIRES, new Date(clock.currentTimeMillis() + TEN_YEARS)); } return response; }
From source file:org.thingsplode.synapse.endpoint.handlers.FileRequestHandler.java
License:Apache License
/** * Sets the Date and Cache headers for the HTTP Response * * @param response HTTP response/*w ww .jav a2 s . c om*/ * @param fileToCache file to extract content type */ public void setDateAndCacheHeaders(HttpResponse response, File fileToCache) { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE)); // Date header Calendar time = new GregorianCalendar(); response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(time.getTime())); // Add cache headers time.add(Calendar.SECOND, HTTP_CACHE_SECONDS); response.headers().set(HttpHeaderNames.EXPIRES, dateFormatter.format(time.getTime())); response.headers().set(HttpHeaderNames.CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS); response.headers().set(HttpHeaderNames.LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified()))); }
From source file:org.waarp.gateway.kernel.http.HttpWriteCacheEnable.java
License:Open Source License
/** * Write a file, taking into account cache enabled and removing session cookie * /* www.ja v a2 s . c o m*/ * @param request * @param ctx * @param filename * @param cookieNameToRemove */ public static void writeFile(HttpRequest request, ChannelHandlerContext ctx, String filename, String cookieNameToRemove) { // Convert the response content to a ByteBuf. HttpResponse response; File file = new File(filename); if (!file.isFile() || !file.canRead()) { response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND); handleCookies(request, response, cookieNameToRemove); ctx.writeAndFlush(response); return; } DateFormat rfc1123Format = new SimpleDateFormat(RFC1123_PATTERN, LOCALE_US); rfc1123Format.setTimeZone(GMT_ZONE); Date lastModifDate = new Date(file.lastModified()); if (request.headers().contains(HttpHeaderNames.IF_MODIFIED_SINCE)) { String sdate = request.headers().get(HttpHeaderNames.IF_MODIFIED_SINCE); try { Date ifmodif = rfc1123Format.parse(sdate); if (ifmodif.after(lastModifDate)) { response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_MODIFIED); handleCookies(request, response, cookieNameToRemove); ctx.writeAndFlush(response); return; } } catch (ParseException e) { } } long size = file.length(); ChunkedNioFile nioFile; try { nioFile = new ChunkedNioFile(file); } catch (IOException e) { response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND); handleCookies(request, response, cookieNameToRemove); ctx.writeAndFlush(response); return; } response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); String type = mimetypesFileTypeMap.getContentType(filename); response.headers().set(HttpHeaderNames.CONTENT_TYPE, type); response.headers().set(HttpHeaderNames.CACHE_CONTROL, cache_control); response.headers().set(HttpHeaderNames.LAST_MODIFIED, rfc1123Format.format(lastModifDate)); handleCookies(request, response, cookieNameToRemove); // Write the response. ctx.write(response); ctx.write(new HttpChunkedInput(nioFile)); ChannelFuture future = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); if (!HttpUtil.isKeepAlive(request)) { // Close the connection when the whole content is written out. future.addListener(ChannelFutureListener.CLOSE); } }