php curl pass through proxy handle: big file, https, autentication
<?php
$url = "http://releases.ubuntu.com/" . $_GET["url"]; $credentials = "user:pwd";
$headers = array(
"GET ".$url." HTTP/1.1",
"Content-type: text/xml",
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Cache-Control: no-cache",
"Pragma: no-cache",
"Authorization: Basic " . base64_encode($credentials)
);
global $filename; $filename = substr($url, strrpos($url, "/")+1); function fn_CURLOPT_WRITEFUNCTION($ch, $str){
$len = strlen($str);
echo( $str );
return $len;
}
function fn_CURLOPT_HEADERFUNCTION($ch, $str){
global $filename;
$len = strlen($str);
header( $str );
if ( strpos($str, "application/x-iso9660-image") !== false ) {
header( "Content-Disposition: attachment; filename=\"$filename\"" ); }
return $len;
}
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_TIMEOUT, 600); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_BUFFERSIZE, 8192); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, "fn_CURLOPT_HEADERFUNCTION"); curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'fn_CURLOPT_WRITEFUNCTION'); if ( ! curl_exec($ch) ) {
error_log( "curl-pass-through-proxy:Error:".curl_error($ch).PHP_EOL, 3, "/tmp/curl-pass-through-proxy.log" );
}
curl_close($ch);