-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #5171 Simplify GzipHandler user-agent handling
+ Remove User-Agent handling from GzipHandler + Allow Vary header to be set + Create rewrite MsieRule to remove Accept-Encoding from IE<=6 Signed-off-by: Greg Wilkins <[email protected]>
- Loading branch information
Showing
14 changed files
with
498 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html | ||
|
||
[description] | ||
Enables the MSIE rewrite rule for MSIE 5 and 6 known bugs. | ||
|
||
[depend] | ||
rewrite | ||
|
||
[files] | ||
basehome:modules/rewrite/rewrite-msie.xml|etc/rewrite-msie.xml | ||
|
||
[xml] | ||
etc/rewrite-msie.xml |
10 changes: 10 additions & 0 deletions
10
jetty-rewrite/src/main/config/modules/rewrite/rewrite-msie.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"> | ||
<Configure id="Rewrite" class="org.eclipse.jetty.rewrite.handler.RuleContainer"> | ||
<Call name="addRule"> | ||
<Arg> | ||
<New class="org.eclipse.jetty.rewrite.handler.MsieRule"/> | ||
</Arg> | ||
</Call> | ||
</Configure> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/MsieRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under | ||
// the terms of the Eclipse Public License 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0 | ||
// | ||
// This Source Code may also be made available under the following | ||
// Secondary Licenses when the conditions for such availability set | ||
// forth in the Eclipse Public License, v. 2.0 are satisfied: | ||
// the Apache License v2.0 which is available at | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.rewrite.handler; | ||
|
||
import java.io.IOException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.eclipse.jetty.http.HttpField; | ||
import org.eclipse.jetty.http.HttpFields; | ||
import org.eclipse.jetty.http.HttpHeader; | ||
import org.eclipse.jetty.http.HttpHeaderValue; | ||
import org.eclipse.jetty.server.Request; | ||
import org.eclipse.jetty.util.ArrayTernaryTrie; | ||
import org.eclipse.jetty.util.Trie; | ||
|
||
/** | ||
* Special handling for MSIE (Microsoft Internet Explorer). | ||
* <ul> | ||
* <li>Disable keep alive for SSL from IE5 or IE6 on Windows 2000</li> | ||
* <li>Disable encodings for IE<=6</li> | ||
* </ul> | ||
*/ | ||
public class MsieRule extends MsieSslRule | ||
{ | ||
private static final int IEv5 = '5'; | ||
private static final int IEv6 = '6'; | ||
private static Trie<Boolean> __IE6_BadOS = new ArrayTernaryTrie<>(); | ||
private static HttpField CONNECTION_CLOSE = new HttpField(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE); | ||
|
||
{ | ||
__IE6_BadOS.put("NT 5.01", Boolean.TRUE); | ||
__IE6_BadOS.put("NT 5.0", Boolean.TRUE); | ||
__IE6_BadOS.put("NT 4.0", Boolean.TRUE); | ||
__IE6_BadOS.put("98", Boolean.TRUE); | ||
__IE6_BadOS.put("98; Win 9x 4.90", Boolean.TRUE); | ||
__IE6_BadOS.put("95", Boolean.TRUE); | ||
__IE6_BadOS.put("CE", Boolean.TRUE); | ||
} | ||
|
||
public MsieRule() | ||
{ | ||
_handling = false; | ||
_terminating = false; | ||
} | ||
|
||
@Override | ||
public String matchAndApply(String target, HttpServletRequest request, HttpServletResponse response) throws IOException | ||
{ | ||
Request baseRequest = Request.getBaseRequest(request); | ||
if (baseRequest == null) | ||
return null; | ||
String userAgent = baseRequest.getHttpFields().get(HttpHeader.USER_AGENT); | ||
|
||
int msie = userAgent.indexOf("MSIE"); | ||
if (msie >= 0) | ||
{ | ||
int version = (userAgent.length() - msie > 5) ? userAgent.charAt(msie + 5) : IEv5; | ||
|
||
if (version <= IEv6) | ||
{ | ||
HttpFields.Mutable fields = HttpFields.build(baseRequest.getHttpFields()); | ||
|
||
// Don't gzip responses for IE<=6 | ||
fields.remove(HttpHeader.ACCEPT_ENCODING); | ||
|
||
// IE<=6 can't do persistent SSL | ||
if (request.isSecure()) | ||
{ | ||
boolean badOs = false; | ||
if (version == IEv6) | ||
{ | ||
int windows = userAgent.indexOf("Windows", msie + 5); | ||
if (windows > 0) | ||
{ | ||
int end = userAgent.indexOf(')', windows + 8); | ||
badOs = (end < 0 || __IE6_BadOS.get(userAgent, windows + 8, end - windows - 8) != null); | ||
} | ||
} | ||
|
||
if (version <= IEv5 || badOs) | ||
{ | ||
fields.remove(HttpHeader.KEEP_ALIVE); | ||
fields.ensure(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.asString()); | ||
response.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString()); | ||
} | ||
} | ||
baseRequest.setHttpFields(fields); | ||
return target; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.