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: 5 additions & 2 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ public function handleClose()
return;
}

// http://chat.stackoverflow.com/transcript/message/7727858#7727858
stream_socket_shutdown($this->stream, STREAM_SHUT_RDWR);
// Try to cleanly shut down socket and ignore any errors in case other
// side already closed. Shutting down may return to blocking mode on
// some legacy versions, so reset to non-blocking just in case before
// continuing to close the socket resource.
@stream_socket_shutdown($this->stream, STREAM_SHUT_RDWR);
stream_set_blocking($this->stream, false);
fclose($this->stream);
}
Expand Down
18 changes: 18 additions & 0 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ public function gettingEncryptedStuffFromGoogleShouldWorkIfHostIsResolvedFirst()
$this->assertRegExp('#^HTTP/1\.0#', $response);
}

/** @test */
public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork()
{
$loop = new StreamSelectLoop();
$connector = new Connector($loop);

$conn = Block\await($connector->connect('google.com:443'), $loop);

$this->assertContains(':443', $conn->getRemoteAddress());
$this->assertNotEquals('google.com:443', $conn->getRemoteAddress());

$conn->write("GET / HTTP/1.0\r\n\r\n");

$response = Block\await(BufferedSink::createPromise($conn), $loop, self::TIMEOUT);

$this->assertNotRegExp('#^HTTP/1\.0#', $response);
}

/** @test */
public function testConnectingFailsIfDnsUsesInvalidResolver()
{
Expand Down