You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2003/05/21 18:43:03 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/request StaticInterceptor.java
marcsaeg 2003/05/21 09:43:02
Modified: src/share/org/apache/tomcat/request Tag: tomcat_32
StaticInterceptor.java
Log:
Added support for the If-Modified-Since header to the FileHandler
servlet wrapper.
NOTE: Tomcat 3.2.x is no longer being actively developed or
maintained. These changes will not appear an any official release.
To get these changes you will need to build Tomcat from source.
Revision Changes Path
No revision
No revision
1.7.2.11 +38 -2 jakarta-tomcat/src/share/org/apache/tomcat/request/Attic/StaticInterceptor.java
Index: StaticInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/Attic/StaticInterceptor.java,v
retrieving revision 1.7.2.10
retrieving revision 1.7.2.11
diff -u -r1.7.2.10 -r1.7.2.11
--- StaticInterceptor.java 30 May 2001 21:33:02 -0000 1.7.2.10
+++ StaticInterceptor.java 21 May 2003 16:43:02 -0000 1.7.2.11
@@ -403,10 +403,34 @@
}
if( debug>0) log( "Serving " + absPath);
- res.setContentType(mimeType);
+ /*
+ * If the request contains an If-Modified-Since header, then we must
+ * compare its value with the file's last modification time. However,
+ * these values can not be directly compares because the file.lasModified()
+ * method returns a value that includes milliseconds and HTTP date headers
+ * MJST NOT include milliseconds. The date returned by Tomcat in the
+ * Last-Modified header truncates * the milliseconds (as opposed to
+ * rounding).
+ *
+ * The following calculation will return a 304 result if the
+ * last modification time is no nore more than 999 milliseconds after
+ * the If-Modified-Since header. Note that this does violate RFC 2616
+ * 14.25 in that If-Modified-Since headers with values in the future
+ * should result in a 200 response, not a 304. The performance impact of
+ * getting the system time for each file seems prohibitive.
+ */
+ long lastModified = file.lastModified();
+ long ifModifiedSince = getDateHeader(req, "If-Modified-Since");
+ if((lastModified - ifModifiedSince) < 1000){
+ res.setStatus(304);
+ res.setContentLength(0);
+ return;
+ }
+
+ res.setContentType(mimeType);
res.setContentLength((int)file.length());
- setDateHeader(res, "Last-Modified", file.lastModified());
+ setDateHeader(res, "Last-Modified", lastModified);
FileInputStream in=null;
try {
@@ -448,6 +472,18 @@
headerF.setName( name );
headerF.setDateValue( value );
}
+
+ static long getDateHeader( Request req, String name)
+ {
+ MimeHeaders headers=req.getMimeHeaders();
+ MimeHeaderField headerF=headers.find( name );
+ if(headerF == null){
+ return -1L;
+ }
+
+ return headerF.getDateValue();
+ }
+
/** All path checks that were part of DefaultServlet
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org