View Javadoc

1   //========================================================================
2   //$Id: MsieSslRule.java 966 2008-04-17 13:53:44Z gregw $
3   //Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
4   //------------------------------------------------------------------------
5   //Licensed under the Apache License, Version 2.0 (the "License");
6   //you may not use this file except in compliance with the License.
7   //You may obtain a copy of the License at 
8   //http://www.apache.org/licenses/LICENSE-2.0
9   //Unless required by applicable law or agreed to in writing, software
10  //distributed under the License is distributed on an "AS IS" BASIS,
11  //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  //See the License for the specific language governing permissions and
13  //limitations under the License.
14  //========================================================================
15  package org.mortbay.jetty.handler.rewrite;
16  
17  import java.io.IOException;
18  
19  import javax.servlet.http.HttpServletRequest;
20  import javax.servlet.http.HttpServletResponse;
21  
22  import org.mortbay.jetty.HttpHeaderValues;
23  import org.mortbay.jetty.HttpHeaders;
24  import org.mortbay.util.StringMap;
25  
26  /**
27   * MSIE (Microsoft Internet Explorer) SSL Rule.
28   * Disable keep alive for SSL from IE5 or IE6 on Windows 2000.
29   *  
30   * @author gregw
31   *
32   */
33  public class MsieSslRule extends Rule
34  {
35      private static final int IEv5 = '5';
36      private static final int IEv6 = '6';
37      private static StringMap __IE6_BadOS = new StringMap();
38      {
39          __IE6_BadOS.put("NT 5.01", Boolean.TRUE);
40          __IE6_BadOS.put("NT 5.0",Boolean.TRUE);
41          __IE6_BadOS.put("NT 4.0",Boolean.TRUE);
42          __IE6_BadOS.put("98",Boolean.TRUE);
43          __IE6_BadOS.put("98; Win 9x 4.90",Boolean.TRUE);
44          __IE6_BadOS.put("95",Boolean.TRUE);
45          __IE6_BadOS.put("CE",Boolean.TRUE);
46      }
47      
48      public MsieSslRule()
49      {
50          _handling = false;
51          _terminating = false;
52      }
53      
54      public String matchAndApply(String target, HttpServletRequest request, HttpServletResponse response) throws IOException
55      {
56          if (request.isSecure())
57          {
58              String user_agent = request.getHeader(HttpHeaders.USER_AGENT);
59              
60              if (user_agent!=null)
61              {
62                  int msie=user_agent.indexOf("MSIE");
63                  if (msie>0 && user_agent.length()-msie>5)
64                  {
65                      // Get Internet Explorer Version
66                      int ieVersion = user_agent.charAt(msie+5);
67                      
68                      if ( ieVersion<=IEv5)
69                      {
70                          response.setHeader(HttpHeaders.CONNECTION, HttpHeaderValues.CLOSE);
71                          return target;
72                      }
73  
74                      if (ieVersion==IEv6)
75                      {
76                          int windows = user_agent.indexOf("Windows",msie+5);
77                          if (windows>0)
78                          {
79                              int end=user_agent.indexOf(')',windows+8);
80                              if(end<0 || __IE6_BadOS.getEntry(user_agent,windows+8,end-windows-8)!=null)
81                              {
82                                  response.setHeader(HttpHeaders.CONNECTION, HttpHeaderValues.CLOSE);
83                                  return target;
84                              }
85                          }
86                      }
87                  }
88              }
89          }
90          return null;
91      }
92  }