|
1 | 1 | <?php |
| 2 | + |
2 | 3 | /* config */ |
3 | 4 | $dest_host = "example.com"; //Destination domain |
4 | 5 | $proxied_headers = array('Set-Cookie', 'Content-Type', 'Cookie', 'Location'); // server -> client |
|
12 | 13 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
13 | 14 | curl_setopt($ch, CURLOPT_HEADER, 1); |
14 | 15 | curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); |
| 16 | +curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); |
| 17 | +curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
15 | 18 |
|
16 | 19 | /* headers */ |
17 | 20 | if(isset($_SERVER['HTTP_COOKIE'])){ |
|
25 | 28 |
|
26 | 29 | $res = curl_exec($ch); |
27 | 30 |
|
| 31 | + |
28 | 32 | curl_close($ch); |
29 | 33 | /* parse response */ |
30 | 34 | list($headers, $body) = explode("\r\n\r\n", $res, 2); |
| 35 | + |
31 | 36 | $headers = explode("\r\n", $headers); |
32 | 37 | $hs = array(); |
33 | 38 | foreach($headers as $header){ |
34 | 39 | if(false !== strpos($header, ':')){ |
35 | 40 | list($h, $v) = explode(':', $header); |
36 | | - $hs[$h] = $v; |
| 41 | + $hs[$h][] = $v; |
37 | 42 | } else { |
38 | | - $header1 = $header; |
| 43 | + $header1 = $header; |
39 | 44 | } |
40 | 45 | } |
41 | 46 |
|
42 | 47 | /* set headers */ |
43 | | -header($header1); |
| 48 | +list($proto, $code, $text) = explode(' ', $header1); |
| 49 | +header($_SERVER['SERVER_PROTOCOL'].' '.$code.' '.$text); |
44 | 50 | foreach($proxied_headers as $hname){ |
45 | 51 | if(isset($hs[$hname])){ |
46 | | - header($hname.": ".$hs[$hname]); |
| 52 | + foreach($hs[$hname] as $v){ |
| 53 | + if($hname === 'Set-Cookie'){ |
| 54 | + header($hname.": ".$v, false); |
| 55 | + }else{ |
| 56 | + header($hname.": ".$v); |
| 57 | + } |
| 58 | + } |
47 | 59 | } |
48 | 60 | } |
49 | 61 |
|
|
0 commit comments