View Javadoc

1   // ========================================================================
2   // $Id$
3   // Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
4   // ------------------------------------------------------------------------
5   // All rights reserved. This program and the accompanying materials
6   // are made available under the terms of the Eclipse Public License v1.0
7   // and Apache License v2.0 which accompanies this distribution.
8   // The Eclipse Public License is available at 
9   // http://www.eclipse.org/legal/epl-v10.html
10  // The Apache License v2.0 is available at
11  // http://www.opensource.org/licenses/apache2.0.php
12  // You may elect to redistribute this code under either of these licenses. 
13  // ========================================================================
14  package org.eclipse.jetty.rewrite.handler;
15  
16  import java.io.IOException;
17  
18  import javax.servlet.http.HttpServletRequest;
19  import javax.servlet.http.HttpServletResponse;
20  
21  import org.eclipse.jetty.http.HttpHeaderValues;
22  import org.eclipse.jetty.http.HttpHeaders;
23  import org.eclipse.jetty.util.StringMap;
24  
25  /**
26   * MSIE (Microsoft Internet Explorer) SSL Rule.
27   * Disable keep alive for SSL from IE5 or IE6 on Windows 2000.
28   *  
29   * 
30   *
31   */
32  public class MsieSslRule extends Rule
33  {
34      private static final int IEv5 = '5';
35      private static final int IEv6 = '6';
36      private static StringMap __IE6_BadOS = new StringMap();
37      {
38          __IE6_BadOS.put("NT 5.01", Boolean.TRUE);
39          __IE6_BadOS.put("NT 5.0",Boolean.TRUE);
40          __IE6_BadOS.put("NT 4.0",Boolean.TRUE);
41          __IE6_BadOS.put("98",Boolean.TRUE);
42          __IE6_BadOS.put("98; Win 9x 4.90",Boolean.TRUE);
43          __IE6_BadOS.put("95",Boolean.TRUE);
44          __IE6_BadOS.put("CE",Boolean.TRUE);
45      }
46      
47      public MsieSslRule()
48      {
49          _handling = false;
50          _terminating = false;
51      }
52      
53      public String matchAndApply(String target, HttpServletRequest request, HttpServletResponse response) throws IOException
54      {
55          if (request.isSecure())
56          {
57              String user_agent = request.getHeader(HttpHeaders.USER_AGENT);
58              
59              if (user_agent!=null)
60              {
61                  int msie=user_agent.indexOf("MSIE");
62                  if (msie>0 && user_agent.length()-msie>5)
63                  {
64                      // Get Internet Explorer Version
65                      int ieVersion = user_agent.charAt(msie+5);
66                      
67                      if ( ieVersion<=IEv5)
68                      {
69                          response.setHeader(HttpHeaders.CONNECTION, HttpHeaderValues.CLOSE);
70                          return target;
71                      }
72  
73                      if (ieVersion==IEv6)
74                      {
75                          int windows = user_agent.indexOf("Windows",msie+5);
76                          if (windows>0)
77                          {
78                              int end=user_agent.indexOf(')',windows+8);
79                              if(end<0 || __IE6_BadOS.getEntry(user_agent,windows+8,end-windows-8)!=null)
80                              {
81                                  response.setHeader(HttpHeaders.CONNECTION, HttpHeaderValues.CLOSE);
82                                  return target;
83                              }
84                          }
85                      }
86                  }
87              }
88          }
89          return null;
90      }
91  }