mirror of
https://github.com/gnh1201/caterpillar.git
synced 2025-02-06 15:05:00 +00:00
Update index.php
This commit is contained in:
parent
b01543899a
commit
07d90b2bfd
25
index.php
25
index.php
|
@ -14,6 +14,22 @@ if (strpos($_SERVER['HTTP_USER_AGENT'], "php-httpproxy/") !== 0) {
|
|||
ini_set("default_socket_timeout", 1); // must be. because of `feof()` works
|
||||
ini_set("max_execution_time", 0);
|
||||
|
||||
function jsonrpc2_encode($params) {
|
||||
$data = array(
|
||||
"jsonrpc" => "2.0",
|
||||
"params" => $params
|
||||
);
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
function jsonrpc2_result_encode($result) {
|
||||
$data = array(
|
||||
"jsonrpc" => "2.0",
|
||||
"result" => $result
|
||||
);
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
function jsonrpc2_error_encode($error) {
|
||||
$data = array(
|
||||
"jsonrpc" => "2.0",
|
||||
|
@ -22,6 +38,7 @@ function jsonrpc2_error_encode($error) {
|
|||
return json_encode($data);
|
||||
}
|
||||
|
||||
|
||||
function parse_headers($str) { // Parses HTTP headers into an array
|
||||
// https://stackoverflow.com/questions/16934409/curl-as-proxy-deal-with-https-connect-method
|
||||
// https://stackoverflow.com/questions/12433958/how-to-parse-response-headers-in-php
|
||||
|
@ -108,8 +125,16 @@ function relay_connect($params) {
|
|||
);
|
||||
echo "HTTP/1.1 400 Bad Request\r\n\r\n" . jsonrpc2_error_encode($error);
|
||||
} else {
|
||||
fwrite($fp, jsonrpc2_result_encode(array("success" => true)));
|
||||
|
||||
$buf = null;
|
||||
while (!feof($fp) && $buf !== false) {
|
||||
$buf = fgets($fp, $buffer_size);
|
||||
// todo
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
// parse context
|
||||
|
|
Loading…
Reference in New Issue
Block a user