Update index.php

This commit is contained in:
Namhyeon Go 2024-02-26 13:55:22 +09:00 committed by GitHub
parent b01543899a
commit 07d90b2bfd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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("default_socket_timeout", 1); // must be. because of `feof()` works
ini_set("max_execution_time", 0); 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) { function jsonrpc2_error_encode($error) {
$data = array( $data = array(
"jsonrpc" => "2.0", "jsonrpc" => "2.0",
@ -22,6 +38,7 @@ function jsonrpc2_error_encode($error) {
return json_encode($data); return json_encode($data);
} }
function parse_headers($str) { // Parses HTTP headers into an array 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/16934409/curl-as-proxy-deal-with-https-connect-method
// https://stackoverflow.com/questions/12433958/how-to-parse-response-headers-in-php // 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); echo "HTTP/1.1 400 Bad Request\r\n\r\n" . jsonrpc2_error_encode($error);
} else { } else {
fwrite($fp, jsonrpc2_result_encode(array("success" => true)));
$buf = null;
while (!feof($fp) && $buf !== false) {
$buf = fgets($fp, $buffer_size);
// todo // todo
} }
fclose($fp);
}
} }
// parse context // parse context