mirror of
https://github.com/gnh1201/caterpillar.git
synced 2025-11-29 10:53:31 +00:00
Update index.php
This commit is contained in:
parent
62fa07baab
commit
029b5543de
25
index.php
25
index.php
|
|
@ -69,15 +69,15 @@ function read_from_remote_server($remote_address, $remote_port, $scheme, $conn =
|
||||||
$sock = fsockopen($remote_address, $remote_port, $error_code, $error_message, 1);
|
$sock = fsockopen($remote_address, $remote_port, $error_code, $error_message, 1);
|
||||||
if (!$sock) {
|
if (!$sock) {
|
||||||
$error = array(
|
$error = array(
|
||||||
"status" => 400,
|
"status" => 502,
|
||||||
"code" => $error_code,
|
"code" => $error_code,
|
||||||
"message" => $error_message
|
"message" => "Bad Gateway"
|
||||||
);
|
);
|
||||||
|
|
||||||
$buf = "HTTP/1.1 400 Bad Request\r\n\r\n" . jsonrpc2_error_encode($error, $id);
|
|
||||||
if ($conn == null) {
|
if ($conn == null) {
|
||||||
echo $buf;
|
echo jsonrpc2_error_encode($error, $id);
|
||||||
} else {
|
} else {
|
||||||
|
$buf = "HTTP/1.1 502 Bad Gateway\r\n\r\n" . jsonrpc2_error_encode($error, $id);
|
||||||
fwrite($conn, $buf);
|
fwrite($conn, $buf);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -121,7 +121,12 @@ function relay_request($params, $id = '') {
|
||||||
|
|
||||||
switch ($request_header['@method'][0]) {
|
switch ($request_header['@method'][0]) {
|
||||||
case "CONNECT":
|
case "CONNECT":
|
||||||
echo sprintf("%s 200 Connection Established\r\n\r\n", $request_header['@method'][2]);
|
$error = array(
|
||||||
|
"status" => 405,
|
||||||
|
"code" => -1,
|
||||||
|
"message" => "Method Not Allowed"
|
||||||
|
);
|
||||||
|
echo jsonrpc2_error_encode($error, $id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -144,16 +149,12 @@ function relay_connect($params, $id = '') {
|
||||||
$conn = fsockopen($client_address, $client_port, $error_code, $error_message, 1);
|
$conn = fsockopen($client_address, $client_port, $error_code, $error_message, 1);
|
||||||
if (!$conn) {
|
if (!$conn) {
|
||||||
$error = array(
|
$error = array(
|
||||||
"success" => false,
|
"status" => 502,
|
||||||
"code" => $error_code,
|
"code" => $error_code,
|
||||||
"message" => $error_message
|
"message" => "Bad Gateway"
|
||||||
);
|
);
|
||||||
fwrite($conn, jsonrpc2_result_encode($error) . "\r\n\r\n");
|
echo jsonrpc2_error_encode($error, $id);
|
||||||
} else {
|
} else {
|
||||||
$result = array(
|
|
||||||
"success" => true
|
|
||||||
);
|
|
||||||
fwrite($conn, jsonrpc2_result_encode($result) . "\r\n\r\n");
|
|
||||||
read_from_remote_server($remote_address, $remote_port, $scheme, $conn, $buffer_size, $id);
|
read_from_remote_server($remote_address, $remote_port, $scheme, $conn, $buffer_size, $id);
|
||||||
fclose($conn);
|
fclose($conn);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user