Bug 48998 - Proposal : port mod_expires in java as ExpiresFilter Servlet Filter
Summary: Proposal : port mod_expires in java as ExpiresFilter Servlet Filter
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: trunk
Hardware: PC Mac OS X 10.4
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-26 16:38 UTC by Cyrille Le Clerc
Modified: 2010-07-14 18:16 UTC (History)
0 users



Attachments
Port of mod_expires as ExpiresFilter (112.14 KB, application/octet-stream)
2010-03-26 16:38 UTC, Cyrille Le Clerc
Details
Port of mod_expires as ExpiresFilter with optimized null checks (94.67 KB, patch)
2010-03-29 18:17 UTC, Cyrille Le Clerc
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Cyrille Le Clerc 2010-03-26 16:38:18 UTC
Created attachment 25189 [details]
Port of mod_expires as ExpiresFilter

Here is a proposal to port Apache Httpd mod_expires in java as ExpiresFilter, a standard Servlet Filter.

I detailed a standalone version on http://code.google.com/p/xebia-france/wiki/ExpiresFilter . More over, I tried my best to provide very detailed javadocs and docs (in filter.html).

The proposed contribution is slightly different because it uses Tomcat logging, few Servlet 3 enhancements and test cases use Tomcat engine.

The attached patch contains :
* ExpiresFilter.java : the Expires Filter
* TestExpiresFilter : detailed test cases
* filter.xml : doc updates

The filter has been optimized using a profiler and stress tested with Apache Bench under high load.
Comment 1 Cyrille Le Clerc 2010-03-29 18:17:29 UTC
Created attachment 25208 [details]
Port of mod_expires as ExpiresFilter with optimized null checks

This patch slightly smaller than previous .patch file because the previous .patch file included twice TestExpiresFilter.java.

Changes in this patch:
* ExpiresFilter.java : reduce null checks for speed optimization,
* filter.xml : add a comment in to warn users not to declare blank chars between ';' and 'charset=' for 'ExpiresByType' directives,
* TestExpiresFilter.java : narrow the precision interval in cache-control checks.
Comment 2 Sylvain Laurent 2010-03-29 18:40:43 UTC
why not use http://tuckey.org/urlrewrite/ ? it can do this and many other things...
Comment 3 Cyrille Le Clerc 2010-03-29 19:02:39 UTC
(In reply to comment #2)
> why not use http://tuckey.org/urlrewrite/ ? it can do this and many other
> things...

My understanding is that the UrlRewriteFilter can add response headers (e.g. 'Expires' and 'Cache-Control') according to request attributes like a URI pattern (e.g. *.html).

However, I don't see how I could express something like "if the response content type is 'application/rss+xml' and if no expiration header has been defined, then add an expiration of 5 minutes".

A challenge I see in this kind of feature is to apply the expiration-header-generation logic just before the servlet engine starts to write in the response body in the socket.
Comment 4 Mark Thomas 2010-07-14 18:16:23 UTC
Thanks for the patch. I have applied it to trunk and it will be included in 7.0.1 onwards.

I did make a few changes:
- fixed various Eclipse warnings
- removed the active option