curl ,response headers and gzip encoding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi i am trying to build a proxy server for opera's turbo mod

<?
error_reporting(0);
$domain='http://
'.@substr($_SERVER['REQUEST_URI'],strlen($_SERVER['SCRIPT_NAME'])+1);
$data=$_SERVER['REQUEST_METHOD'].' '.$domain;$data=$data.' HTTP/1.1';
$domainadi=@parse_url($domain) or die('Hata Kod :
4');$domainadi=$domainadi['host'];
if(empty($domain)) { die('Hata Kod : 4'); }
foreach (getallheaders() as $name => $value) {
$data.= "\n$name: $value";
}
$data=str_replace('Host: w.com','Host: '.$domainadi,$data);
$data.="\r\n\r\n";
if($_SERVER['REQUEST_METHOD']=='POST') {
$data.=@file_get_contents('php://input'); }


#echo $domain;exit;
#echo $data;exit;



$ch = curl_init($domain);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if($_SERVER['REQUEST_METHOD']=='POST') { curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, @file_get_contents('php://input')); }
$header = array();
foreach(getallheaders() as $key => $value)
{
if(strtolower($key)!='host')
{
$header[] = $key . ':' . $value;
}
}
curl_setopt($ch , CURLOPT_HTTPHEADER , $header);
$donen=@curl_exec($ch);

#header('Content-Encoding: gzip');
if(curl_getinfo($ch,CURLINFO_HTTP_CODE)=='0') die('Hata Kod:36');
@list($reshead, $body) = @explode("\r\n\r\n", $donen, 2) or die('Hata Kod
:37');

$info = curl_getinfo($ch);
$reshead = substr($donen, 0, $info['header_size']);
$body = substr($donen, $info['header_size']);


$headerlar=explode("\n",$reshead);
for($i=0;$i<count($headerlar);$i++)
{
header(trim($headerlar[$i]));
}
header('X-Opera-Host: v07-16:12419');header('X-Opera-Info:
ID=2');header('X-OA:
8ebe63c71408d41bfa10d4fef52ea7bb961b2d22cf6cb823d1845f2be63e1950');


echo $body;
curl_close($ch);
?>


it returns the gzip content as damaged may be for split the headers and
body ,
,
when i take   curl_setopt($ch, CURLOPT_HEADER, 0); to   curl_setopt($ch,
CURLOPT_HEADER, 1);
  header('Content-Encoding: gzip'); uncomment this line
hide these lines

/*
if(curl_getinfo($ch,CURLINFO_HTTP_CODE)=='0') die('Hata Kod:36');
@list($reshead, $body) = @explode("\r\n\r\n", $donen, 2) or die('Hata Kod
:37');

$info = curl_getinfo($ch);
$reshead = substr($donen, 0, $info['header_size']);
$body = substr($donen, $info['header_size']);


$headerlar=explode("\n",$reshead);
for($i=0;$i<count($headerlar);$i++)
{
header(trim($headerlar[$i]));
}
*/
and return the original content   echo $donen; curl_close($ch);

it works nice,

but i cant forward the headers to client :( and not sure why the original
scripts returns the gzip content as damaged :/

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux