1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-24 14:42:50 +02:00

Joe Lencioni's patch for issue 5

This commit is contained in:
Steve Clay
2011-10-13 20:11:38 -04:00
parent fbc20ab19d
commit 3c5543c3ea

View File

@@ -74,15 +74,32 @@ class Minify_JS_ClosureCompiler {
protected function _getResponse($postBody) protected function _getResponse($postBody)
{ {
$contents = file_get_contents(self::URL, false, stream_context_create(array( $allowUrlFopen = preg_match('/1|yes|on|true/i', ini_get('allow_url_fopen'));
'http' => array( if ($allowUrlFopen) {
'method' => 'POST', $contents = file_get_contents(self::URL, false, stream_context_create(array(
'header' => 'Content-type: application/x-www-form-urlencoded', 'http' => array(
'content' => $postBody, 'method' => 'POST',
'max_redirects' => 0, 'header' => 'Content-type: application/x-www-form-urlencoded',
'timeout' => 15, 'content' => $postBody,
) 'max_redirects' => 0,
))); 'timeout' => 15,
)
)));
} elseif (defined('CURLOPT_POST')) {
$ch = curl_init(self::URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
$contents = curl_exec($ch);
curl_close($ch);
} else {
throw new Minify_JS_ClosureCompiler_Exception(
"Could not make HTTP request: allow_url_open is false and cURL not available"
);
}
if (false === $contents) { if (false === $contents) {
throw new Minify_JS_ClosureCompiler_Exception( throw new Minify_JS_ClosureCompiler_Exception(
"No HTTP response from server" "No HTTP response from server"