Skip to content

Commit

Permalink
Merge branch 'master' of github.com:walkor/workerman
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Jul 4, 2024
2 parents 259aab0 + 751c1d1 commit 4ab33a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Connection/AsyncTcpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Protocols/Http/mime.types
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4ab33a6

Please sign in to comment.