1
0
mirror of https://github.com/mrclay/minify.git synced 2025-02-24 00:44:32 +01:00

Issue 57 work. Min app sets "zlib.output_compression" to "0" in case it is "1". Builder doesn't encode is it senses this option set, and runs AJAX checks for the status of it and to check for double-encoded output.

This commit is contained in:
Steve Clay 2008-10-07 15:07:13 +00:00
parent 0fe53c9813
commit 6b2ecd4038
3 changed files with 71 additions and 0 deletions

View File

@ -1,5 +1,8 @@
<?php
// check for auto-encoding
$encodeOutput = ! ini_get('zlib.output_compression');
require dirname(__FILE__) . '/../config.php';
if (! $min_enableBuilder) {
@ -28,6 +31,7 @@ h1 {margin-top:0;}
#groupConfig {font-family:monospace;}
b {color:#c00}
.topNote {background: #ff9; display:inline-block; padding:.5em .6em; margin:0 0 1em;}
.topWarning {background:#c00; color:#fff; padding:.5em .6em; margin:0 0 1em;}
</style>
</head>
@ -110,6 +114,35 @@ source</a></small></p>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
// detection of double output encoding
var msg = '<p class=topWarning><strong>Warning:</strong> ';
var url = 'ocCheck.php?' + (new Date()).getTime();
$.get(url, function (ocStatus) {
$.get(url + '&hello=1', function (ocHello) {
if (ocHello != 'World!') {
msg += 'It appears output is being automatically compressed, interfering '
+ ' with Minify\'s own compression. ';
if (ocStatus == '1')
msg += 'The option "zlib.output_compression" is enabled in your PHP configuration. '
+ 'Minify set this to "0", but it had no effect. This option must be disabled '
+ 'in php.ini or .htaccess.';
else
msg += 'The option "zlib.output_compression" is disabled in your PHP configuration '
+ 'so this behavior is likely due to a server option.';
$(document.body).prepend(msg + '</p>');
} else
if (ocStatus == '1')
$(document.body).prepend('<p class=topNote><strong>Note:</strong> The option '
+ '"zlib.output_compression" is enabled in your PHP configuration, but has been '
+ 'successfully disabled via ini_set(). If you experience mangled output you '
+ 'may want to consider disabling this option in your PHP configuration.'
);
});
});
});
</script>
<script type="text/javascript">
// workaround required to test when /min isn't child of web root
var src = location.pathname.replace(/\/[^\/]*$/, '/_index.js').substr(1);
@ -127,6 +160,7 @@ $serveOpts = array(
,filemtime(dirname(__FILE__) . '/../config.php')
)
,'minifyAll' => true
,'encodeOutput' => $encodeOutput
);
ob_end_clean();

34
min/builder/ocCheck.php Normal file
View File

@ -0,0 +1,34 @@
<?php
/**
* AJAX checks for zlib.output_compression
*
* @package Minify
*/
// allow access only if builder is enabled
require dirname(__FILE__) . '/../config.php';
if (! $min_enableBuilder) {
header('Location: /');
exit();
}
if (isset($_GET['hello'])) {
// echo 'World!'
// try to prevent double encoding (may not have an effect)
ini_set('zlib.output_compression', '0');
require $min_libPath . '/HTTP/Encoder.php';
HTTP_Encoder::$encodeToIe6 = true; // just in case
$he = new HTTP_Encoder(array(
'content' => 'World!'
,'method' => 'deflate'
));
$he->encode();
$he->sendAll();
} else {
// echo status "0" or "1"
header('Content-Type: text/plain');
echo (int)ini_get('zlib.output_compression');
}

View File

@ -9,6 +9,9 @@
define('MINIFY_MIN_DIR', dirname(__FILE__));
// try to disable output_compression (may not have an effect)
ini_set('zlib.output_compression', '0');
// load config
require MINIFY_MIN_DIR . '/config.php';