Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Connection/DefaultConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Amp\Http\Client\Request;
use Amp\Http\Client\SocketException;
use Amp\Http\Client\TimeoutException;
use Amp\Http\Client\TlsException;
use Amp\Socket;
use Amp\Socket\ClientTlsContext;
use Amp\Socket\ConnectContext;
Expand Down Expand Up @@ -123,7 +124,7 @@ public function create(Request $request, Cancellation $cancellation): Connection
if ($tlsState !== Socket\TlsState::Disabled) {
$socket->close();

throw new SocketException('Failed to setup TLS connection, connection was in an unexpected TLS state (' . $tlsState->name . ')');
throw new TlsException('Failed to setup TLS connection, connection was in an unexpected TLS state (' . $tlsState->name . ')');
}

$socket->setupTls(new CompositeCancellation(
Expand All @@ -137,7 +138,7 @@ public function create(Request $request, Cancellation $cancellation): Connection
\preg_match('/error:[0-9a-f]*:[^:]*:[^:]*:(.+)$/i', $errorMessage, $matches);
$errorMessage = \trim($matches[1] ?? \explode('():', $errorMessage, 2)[1] ?? $errorMessage);

throw new SocketException(\sprintf(
throw new TlsException(\sprintf(
"Connection to '%s' @ '%s' closed during TLS handshake: %s",
$authority,
$socket->getRemoteAddress()->toString(),
Expand All @@ -161,7 +162,7 @@ public function create(Request $request, Cancellation $cancellation): Connection
if ($tlsInfo === null) {
$socket->close();

throw new SocketException(\sprintf(
throw new TlsException(\sprintf(
"Socket closed after TLS handshake with '%s' @ '%s'",
$authority,
$socket->getRemoteAddress()->toString()
Expand Down
2 changes: 1 addition & 1 deletion src/SocketException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace Amp\Http\Client;

final class SocketException extends HttpException
class SocketException extends HttpException
{
}
7 changes: 7 additions & 0 deletions src/TlsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php declare(strict_types=1);

namespace Amp\Http\Client;

final class TlsException extends SocketException
{
}
6 changes: 3 additions & 3 deletions test/ClientBadSslIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testSelfSignedCertificate(): void
{
$request = new Request('https://self-signed.badssl.com/');

$this->expectException(SocketException::class);
$this->expectException(TlsException::class);
$this->expectExceptionMessageMatches("/^Connection to 'self-signed.badssl.com:443' @ '.+' closed during TLS handshake: certificate verify failed$/");

$this->client->request($request);
Expand All @@ -29,7 +29,7 @@ public function testWrongHostCertificate(): void
{
$request = new Request('https://wrong.host.badssl.com/');

$this->expectException(SocketException::class);
$this->expectException(TlsException::class);
$this->expectExceptionMessageMatches("/^Connection to 'wrong.host.badssl.com:443' @ '.+' closed during TLS handshake: Peer certificate CN=`\*.badssl.com' did not match expected CN=`wrong.host.badssl.com'$/");

$this->client->request($request);
Expand All @@ -39,7 +39,7 @@ public function testDhKeyTooSmall(): void
{
$request = new Request('https://dh512.badssl.com/');

$this->expectException(SocketException::class);
$this->expectException(TlsException::class);
$this->expectExceptionMessageMatches("/^Connection to 'dh512.badssl.com:443' @ '.+' closed during TLS handshake: dh key too small$/");

$this->client->request($request);
Expand Down