Fix websockets

This commit is contained in:
Daniil Gentili 2019-12-13 17:26:08 +01:00
parent a7b0a16a01
commit 069c599a7c
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 10 additions and 5 deletions

View File

@ -31,6 +31,8 @@ use Amp\Http\Client\Cookie\CookieJar;
use Amp\Http\Client\Cookie\InMemoryCookieJar;
use Amp\Http\Client\DelegateHttpClient;
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Interceptor\ModifyRequest;
use Amp\Http\Client\Interceptor\RemoveRequestHeader;
use Amp\Http\Client\Request;
use Amp\Socket\ConnectContext;
use Amp\Websocket\Client\Rfc6455Connector;

View File

@ -180,7 +180,7 @@ class Magic
$DohConfig = new DoHConfig(
[
new Nameserver('https://mozilla.cloudflare-dns.com/dns-query'),
new Nameserver('https://google.com/resolve', Nameserver::GOOGLE_JSON, ["Host" => "dns.google.com"]),
new Nameserver('https://dns.google/resolve'),
]
);
resolver(new Rfc8484StubResolver($DohConfig));

View File

@ -20,6 +20,7 @@ namespace danog\MadelineProto\Stream\Transport;
use Amp\Promise;
use Amp\Socket\EncryptableSocket;
use Amp\Websocket\Client\Connector;
use Amp\Websocket\Client\Handshake;
use danog\MadelineProto\Stream\Async\RawStream;
use danog\MadelineProto\Stream\ConnectionContext;
@ -67,8 +68,8 @@ class WsStream implements RawStreamInterface, ProxyStreamInterface
{
$this->dc = $ctx->getIntDc();
$handshake = new Handshake(\str_replace('tcp://', $ctx->isSecure() ? 'ws://' : 'wss://', $ctx->getStringUri()));
$handshake = new Handshake(\str_replace('tcp://', $ctx->isSecure() ? 'wss://' : 'ws://', $ctx->getStringUri()));
$this->stream = yield ($this->connector ?? connector())->connect($handshake, $ctx->getCancellationToken());
yield $this->write($header);
@ -96,7 +97,7 @@ class WsStream implements RawStreamInterface, ProxyStreamInterface
$data = yield $this->message->buffer();
$this->message = null;
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
if ($e->getReason() !== 'Client closed the underlying TCP connection') {
throw $e;
}
@ -129,7 +130,9 @@ class WsStream implements RawStreamInterface, ProxyStreamInterface
}
public function setExtra($extra)
{
$this->connector = $extra;
if ($extra instanceof Connector) {
$this->connector = $extra;
}
}
public static function getName(): string