From 1eda02e61b75678d562e86123eb24dcd8ce02894 Mon Sep 17 00:00:00 2001 From: roiwk Date: Thu, 11 Apr 2024 14:54:05 +0800 Subject: [PATCH 1/2] fix(async tcp): proxy --- src/Connection/AsyncTcpConnection.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Connection/AsyncTcpConnection.php b/src/Connection/AsyncTcpConnection.php index e88b2c098..14ff8a460 100644 --- a/src/Connection/AsyncTcpConnection.php +++ b/src/Connection/AsyncTcpConnection.php @@ -261,19 +261,10 @@ public function connect(): void $this->socketContext['ssl']['peer_name'] = $this->remoteHost; $context = stream_context_create($this->socketContext); $this->socket = stream_socket_client("tcp://$this->proxySocks5", $errno, $err_str, 0, STREAM_CLIENT_ASYNC_CONNECT, $context); - fwrite($this->socket, chr(5) . chr(1) . chr(0)); - fread($this->socket, 512); - fwrite($this->socket, chr(5) . chr(1) . chr(0) . chr(3) . chr(strlen($this->remoteHost)) . $this->remoteHost . pack("n", $this->remotePort)); - fread($this->socket, 512); } else if ($this->proxyHttp) { $this->socketContext['ssl']['peer_name'] = $this->remoteHost; $context = stream_context_create($this->socketContext); $this->socket = stream_socket_client("tcp://$this->proxyHttp", $errno, $err_str, 0, STREAM_CLIENT_ASYNC_CONNECT, $context); - $str = "CONNECT $this->remoteHost:$this->remotePort HTTP/1.1\n"; - $str .= "Host: $this->remoteHost:$this->remotePort\n"; - $str .= "Proxy-Connection: keep-alive\n"; - fwrite($this->socket, $str); - fread($this->socket, 512); } else if ($this->socketContext) { $context = stream_context_create($this->socketContext); $this->socket = stream_socket_client("tcp://$this->remoteHost:$this->remotePort", @@ -377,6 +368,20 @@ public function checkConnection(): void // Check socket state. if ($address = stream_socket_get_name($this->socket, true)) { + // Proxy + if ($this->proxySocks5 && $address === $this->proxySocks5) { + fwrite($this->socket, chr(5) . chr(1) . chr(0)); + fread($this->socket, 512); + fwrite($this->socket, chr(5) . chr(1) . chr(0) . chr(3) . chr(strlen($this->remoteHost)) . $this->remoteHost . pack("n", $this->remotePort)); + fread($this->socket, 512); + } + if ($this->proxyHttp && $address === $this->proxyHttp) { + $str = "CONNECT $this->remoteHost:$this->remotePort HTTP/1.1\r\n"; + $str .= "Host: $this->remoteHost:$this->remotePort\r\n"; + $str .= "Proxy-Connection: keep-alive\r\n\r\n"; + fwrite($this->socket, $str); + fread($this->socket, 512); + } // Nonblocking. stream_set_blocking($this->socket, false); // Compatible with hhvm From 93416483458927512d8a0e17c06d714a2e27dc49 Mon Sep 17 00:00:00 2001 From: NitronPlus <1940394+NitronPlus@users.noreply.github.com> Date: Fri, 19 Apr 2024 17:54:19 +0800 Subject: [PATCH 2/2] Update mime.types Add wasm mime type --- src/Protocols/Http/mime.types | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Protocols/Http/mime.types b/src/Protocols/Http/mime.types index e6ccf0ab1..57699149b 100644 --- a/src/Protocols/Http/mime.types +++ b/src/Protocols/Http/mime.types @@ -8,6 +8,7 @@ types { application/javascript js; application/atom+xml atom; application/rss+xml rss; + application/wasm wasm; text/mathml mml; text/plain txt;