From 7057c59f3d56210dfb9267c8c0a7275e8c647463 Mon Sep 17 00:00:00 2001 From: Veebs Date: Thu, 13 Oct 2011 16:54:08 +1100 Subject: [PATCH] Fixed bug in static file server timestamp comparision before sending back a 304 Not Modified. Only compare upto seconds. --- .../example/http/file/HttpStaticFileServerHandler.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jboss/netty/example/http/file/HttpStaticFileServerHandler.java b/src/main/java/org/jboss/netty/example/http/file/HttpStaticFileServerHandler.java index 922f0be479..f3cf358bcd 100644 --- a/src/main/java/org/jboss/netty/example/http/file/HttpStaticFileServerHandler.java +++ b/src/main/java/org/jboss/netty/example/http/file/HttpStaticFileServerHandler.java @@ -142,8 +142,11 @@ public class HttpStaticFileServerHandler extends SimpleChannelUpstreamHandler { { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); Date ifModifiedSinceDate = dateFormatter.parse(ifModifiedSince); - if (ifModifiedSinceDate.getTime() == file.lastModified()) - { + + // Only compare up to the second because the datetime format we send to the client does not have milliseconds + long ifModifiedSinceDateSeconds = ifModifiedSinceDate.getTime() / 1000; + long fileLastModifiedSeconds = file.lastModified() / 1000; + if (ifModifiedSinceDateSeconds == fileLastModifiedSeconds) { sendNotModified(ctx); return; }