1
0
Fork 0
mirror of https://github.com/GeoffreyFrogeye/phroxyp.git synced 2024-12-03 21:26:05 +01:00

Support for virtually any content

Why haven't I figured out that my server supported this from the
beginning?
This commit is contained in:
Geoffrey Frogeye 2015-04-09 23:56:45 +02:00
parent 57b3a27de3
commit 188431cd4a

View file

@ -47,47 +47,18 @@ class Proxy {
switch ($name) { switch ($name) {
case 'Host': case 'Host':
case 'Connection': case 'Connection':
case 'Content-Length':
break; break;
default: default:
$reqHeds .= "$name: $content\r\n"; $reqHeds .= "$name: $content\r\n";
} }
} }
if (isset($reqsHedsC['Content-Type'])) { $reqHeds .= "Connection: Close\r\n\r\n".file_get_contents('php://input');
switch ($reqsHedsC['Content-Type']) { // TODO Other content-types
case 'application/x-www-form-urlencoded':
$postData = '';
foreach ($_POST as $key => $value) {
$postData .= $key . '=' . urlencode($value) . '&';
}
$postData = rtrim($postData, '&');
break;
case 'application/json':
$postData = file_get_contents('php://input');
break;
case 'TODO':
$postData = stripslashes($_POST['payload']);
break;
default:
$postData = "Unknown Content-Type";
break;
}
$reqHeds .= "Content-Length: ".strlen($postData)."\r\n";
$reqHeds .= "Connection: Close\r\n";
$reqHeds .= "\r\n" . $postData;
} else {
$reqHeds .= "Connection: Close\r\n\r\n";
}
$fp = fsockopen($serv, $port, $errno, $errstr, 30); $fp = fsockopen($serv, $port, $errno, $errstr, 30);
if (!$fp) { // TODO ErrorCode, ErrorDocument if (!$fp) { // TODO ErrorCode, ErrorDocument
echo "Couldn't connect to server\n<br/>$errstr ($errno)<br />\n"; echo "Couldn't connect to server.\n<br/>$errstr ($errno)<br />\n";
} else { } else {
// Sending request // Sending request
fwrite($fp, $reqHeds); fwrite($fp, $reqHeds);