diff --git a/min/lib/HTTP/Encoder.php b/min/lib/HTTP/Encoder.php index 93c7a80..6f4683e 100644 --- a/min/lib/HTTP/Encoder.php +++ b/min/lib/HTTP/Encoder.php @@ -36,6 +36,23 @@ */ class HTTP_Encoder { + /** + * Should the encoder allow HTTP encoding to IE6? + * + * If you have many IE6 users and the bandwidth savings is worth troubling + * some of them, set this to true. + * + * By default, encoding is only offered to IE7+. When this is true, + * getAcceptedEncoding() will return an encoding for IE6 if its user agent + * string contains "SV1". This has been documented in many places as "safe", + * but there seem to be remaining, intermittent encoding bugs in patched + * IE6 on the wild web. + * + * @var int + */ + public static $encodeToIe6 = false; + + /** * Default compression level for zlib operations * @@ -44,6 +61,7 @@ class HTTP_Encoder { * @var int */ public static $compressionLevel = 6; + /** * Get an HTTP Encoder object @@ -258,9 +276,8 @@ class HTTP_Encoder { } // no regex = faaast $version = (float)substr($ua, 30); - return ( - $version < 6 - || ($version == 6 && false === strpos($ua, 'SV1')) - ); + return self::$encodeToIe6 + ? ($version < 6 || ($version == 6 && false === strpos($ua, 'SV1'))) + : ($version < 7); } } diff --git a/min_extras/unit_tests/_test_files/importProcessor/output.css b/min_extras/unit_tests/_test_files/importProcessor/output.css index 695964a..1f690af 100644 --- a/min_extras/unit_tests/_test_files/importProcessor/output.css +++ b/min_extras/unit_tests/_test_files/importProcessor/output.css @@ -1,7 +1,7 @@ @media screen { /* some CSS to try to exercise things in general */ -@import url(/_3rd_party/minify/min_extras/unit_tests/_test_files/css/more.css); +@import url(%TEST_FILES_URI%/css/more.css); body, td, th { font-family: Verdana , "Bitstream Vera Sans" , sans-serif ; @@ -32,17 +32,17 @@ h1 + p { } @import url(http://example.com/hello.css); adjacent foo { background: red url(/red.gif); } -adjacent bar { background: url('/_3rd_party/minify/min_extras/unit_tests/_test_files/importProcessor/../green.gif') } +adjacent bar { background: url('%TEST_FILES_URI%/importProcessor/../green.gif') } } @media tv,projection { -/* @import url('/_3rd_party/minify/min_extras/unit_tests/_test_files/importProcessor/1/bad.css') bad; */ +/* @import url('%TEST_FILES_URI%/importProcessor/1/bad.css') bad; */ adjacent2 foo { background: red url(/red.gif); } -adjacent2 bar { background: url('/_3rd_party/minify/min_extras/unit_tests/_test_files/importProcessor/1/../green.gif') } +adjacent2 bar { background: url('%TEST_FILES_URI%/importProcessor/1/../green.gif') } @import '../input.css'; tv foo { background: red url(/red.gif); } -tv bar { background: url('/_3rd_party/minify/min_extras/unit_tests/_test_files/importProcessor/1/../green.gif') } +tv bar { background: url('%TEST_FILES_URI%/importProcessor/1/../green.gif') } } input foo { background: red url(/red.gif); } -input bar { background: url('/_3rd_party/minify/min_extras/unit_tests/_test_files/importProcessor/../green.gif') } \ No newline at end of file +input bar { background: url('%TEST_FILES_URI%/importProcessor/../green.gif') } \ No newline at end of file diff --git a/min_extras/unit_tests/test_HTTP_Encoder.php b/min_extras/unit_tests/test_HTTP_Encoder.php index 3a114ad..d16b762 100644 --- a/min_extras/unit_tests/test_HTTP_Encoder.php +++ b/min_extras/unit_tests/test_HTTP_Encoder.php @@ -7,6 +7,7 @@ function test_HTTP_Encoder() { global $thisDir; + HTTP_Encoder::$encodeToIe6 = true; $methodTests = array( array( 'ua' => 'Any browser' @@ -51,7 +52,28 @@ function test_HTTP_Encoder() ,'desc' => 'Opera identifying as IE6' ) ); - + foreach ($methodTests as $test) { + $_SERVER['HTTP_USER_AGENT'] = $test['ua']; + $_SERVER['HTTP_ACCEPT_ENCODING'] = $test['ae']; + $exp = $test['exp']; + $ret = HTTP_Encoder::getAcceptedEncoding(); + $passed = assertTrue($exp == $ret, 'HTTP_Encoder : ' . $test['desc']); + + if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { + echo "\n--- AE | UA = {$test['ae']} | {$test['ua']}\n"; + echo "Expected = " . preg_replace('/\\s+/', ' ', var_export($exp, 1)) . "\n"; + echo "Returned = " . preg_replace('/\\s+/', ' ', var_export($ret, 1)) . "\n\n"; + } + } + HTTP_Encoder::$encodeToIe6 = false; + $methodTests = array( + array( + 'ua' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)' + ,'ae' => 'gzip, deflate' + ,'exp' => array('', '') + ,'desc' => 'IE6 w/ "enhanced security"' + ) + ); foreach ($methodTests as $test) { $_SERVER['HTTP_USER_AGENT'] = $test['ua']; $_SERVER['HTTP_ACCEPT_ENCODING'] = $test['ae'];