KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > webdav > filter > NoCacheFilter


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/filter/NoCacheFilter.java,v 1.1.2.1 2004/08/18 21:07:09 masonjm Exp $
3  * $Revision: 1.1.2.1 $
4  * $Date: 2004/08/18 21:07:09 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.webdav.filter;
25
26 import java.io.IOException JavaDoc;
27
28 import javax.servlet.Filter JavaDoc;
29 import javax.servlet.FilterChain JavaDoc;
30 import javax.servlet.FilterConfig JavaDoc;
31 import javax.servlet.ServletException JavaDoc;
32 import javax.servlet.ServletRequest JavaDoc;
33 import javax.servlet.ServletResponse JavaDoc;
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36
37 /**
38  * <p>
39  * A simple filter that ensures the two HTTP cache headers
40  * (Pragma and Cache-Control) are set to values that will allow Internet
41  * Explorer to display non-inline files (.pdf, .doc, etc) when using an SSL
42  * connection. This is to work around a bug in IE versions 5.01 through 6.
43  * </p>
44  *
45  * <p>
46  * This class is designed for use in an intranet environment where the
47  * security ramifications are controllable. In a public environment something
48  * more advanced should be used. Setting Cache-Control to "private" and sniffing
49  * the request to make sure the headers need to be modified might be enough.
50  * </p>
51  *
52  * @see http://support.microsoft.com/default.aspx?scid=KB;EN-US;q316431&
53  *
54  */

55 public class NoCacheFilter implements Filter JavaDoc {
56
57     /**
58      * Does nothing.
59      * @param config is ignored
60      */

61     public void init(FilterConfig JavaDoc config) throws ServletException JavaDoc {
62         // Do nothing
63
}
64
65     /**
66      * Sets the Pragma and Cache-Control HTTP headers then calls the
67      * next Filter in the chain.
68      * @param req the HTTP request
69      * @param resp the HTTP response
70      * @param chain the chain of filter objects handling this request.
71      */

72     public void doFilter(ServletRequest JavaDoc req, ServletResponse JavaDoc resp, FilterChain JavaDoc chain) throws IOException JavaDoc, ServletException JavaDoc {
73         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc)req;
74         HttpServletResponse JavaDoc response = (HttpServletResponse JavaDoc)resp;
75         
76         /*
77          * Ensure headers are set to values that will allow IE to cache the
78          * document. There could be a browser sniff here and a check for the
79          * type of document being requested.
80          */

81         response.setHeader("Pragma", "public");
82         response.setHeader("Cache-Control", "public");
83
84         /*
85          * This must be called after the headers are set because the response
86          * is committed before control returns to this method.
87          */

88         chain.doFilter(req,resp);
89     }
90
91     /**
92      * Does nothing.
93      */

94     public void destroy() {
95         // Do nothing
96
}
97
98 }
99
Popular Tags