billbarker 02/04/26 20:45:19
Modified: src/facade22/org/apache/tomcat/facade
HttpServletRequestFacade.java
src/share/org/apache/tomcat/core Request.java
src/share/org/apache/tomcat/modules/generators
StaticInterceptor.java
Log:
Move the DateFormatters from the Facade to the core Request.
This makes them available for non-servlet Handlers (i.e. StaticInterceptor) as well.
Fix for bug #8562.
Reported By: Pierre OBLIN [EMAIL PROTECTED]
Revision Changes Path
1.33 +1 -17
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpServletRequestFacade.java
Index: HttpServletRequestFacade.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpServletRequestFacade.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- HttpServletRequestFacade.java 22 Mar 2002 02:54:34 -0000 1.32
+++ HttpServletRequestFacade.java 27 Apr 2002 03:45:18 -0000 1.33
@@ -96,7 +96,6 @@
ServletInputStreamFacade isFacade=new ServletInputStreamFacade();
boolean isFacadeInitialized=false;
BufferedReader reader=null;
- DateFormat []dateFormats;
UEncoder uencoder;
private boolean usingStream = false;
@@ -111,13 +110,6 @@
isFacade.setRequest( request );
try {
// we may create facades more often than requests
- if( dateFormats==null ) {
- dateFormats=new DateFormat[] {
- new SimpleDateFormat(DateTool.RFC1123_PATTERN, Locale.US),
- new SimpleDateFormat(DateTool.rfc1036Pattern, Locale.US),
- new SimpleDateFormat(DateTool.asctimePattern, Locale.US)
- };
- }
if( uencoder==null ) {
uencoder=new UEncoder();
uencoder.addSafeCharacter(';');
@@ -216,15 +208,7 @@
* We delegate this to RequestUtil. ( adapter function )
*/
public long getDateHeader(String name) {
- String value=request.getHeader( name );
- if( value==null) return -1;
-
- long date=DateTool.parseDate(value,dateFormats);
- if( date==-1) {
- String msg = sm.getString("httpDate.pe", value);
- throw new IllegalArgumentException(msg);
- }
- return date;
+ return request.getDateHeader( name );
}
public String getHeader(String name) {
1.115 +26 -0 jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java
Index: Request.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -r1.114 -r1.115
--- Request.java 21 Apr 2002 05:56:10 -0000 1.114
+++ Request.java 27 Apr 2002 03:45:18 -0000 1.115
@@ -75,6 +75,9 @@
import java.io.CharConversionException;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Locale;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
/**
* This is a low-level, efficient representation of a server request. Most fields
@@ -219,6 +222,7 @@
protected Request parent;
protected Request child;
+ protected DateFormat []dateFormats = null;
protected UDecoder urlDecoder;
// Error handling support
@@ -891,6 +895,28 @@
}
// -------------------- Facade for MimeHeaders
+ /**
+ * Utility method to parse dates.
+ */
+ public long getDateHeader(String name) {
+ MessageBytes value=getMimeHeaders().getValue( name );
+ if( value==null || value.isNull() ) return -1;
+
+ // By delaying until here, we don't have to create them on sub-requests
+ if( dateFormats == null) {
+ dateFormats=new DateFormat[] {
+ new SimpleDateFormat(DateTool.RFC1123_PATTERN, Locale.US),
+ new SimpleDateFormat(DateTool.rfc1036Pattern, Locale.US),
+ new SimpleDateFormat(DateTool.asctimePattern, Locale.US)
+ };
+ }
+ long date=DateTool.parseDate(value.toString(),dateFormats);
+ if( date==-1) {
+ String msg = response.sm.getString("httpDate.pe", value);
+ throw new IllegalArgumentException(msg);
+ }
+ return date;
+ }
/** @deprecated
*/
public Enumeration getHeaders(String name) {
1.23 +7 -14
jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/StaticInterceptor.java
Index: StaticInterceptor.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/StaticInterceptor.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- StaticInterceptor.java 27 Apr 2002 01:55:18 -0000 1.22
+++ StaticInterceptor.java 27 Apr 2002 03:45:19 -0000 1.23
@@ -335,21 +335,14 @@
File file = new File( absPath );
// If we are included, the If-Modified-Since isn't for us.
if( ! res.isIncluded() ) {
- MessageBytes imsMB=req.getMimeHeaders().getValue("If-Modified-Since");
-
- if (imsMB != null) {
-
- long date = imsMB.getTime();
-
- if ((file.lastModified() <= (date + 1000)) ) {
- // The entity has not been modified since the date
- // specified by the client. This is not an error case.
- context.getContextManager().handleStatus( req, res, 304);
- return;
- }
-
-
+ long date = req.getDateHeader("If-Modified-Since");
+ if ((file.lastModified() <= (date + 1000)) ) {
+ // The entity has not been modified since the date
+ // specified by the client. This is not an error case.
+ context.getContextManager().handleStatus( req, res, 304);
+ return;
}
+
}
if( debug>0) log( "After paranoic checks = " + absPath);
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>