private function parseSocketData(HttpTunnelStruct $struct, $data)
{
try {
$struct->parser->buffer($data);
if (!($parsedResponseArr = $struct->parser->parse())) {
return;
}
$status = $parsedResponseArr['status'];
if ($status == 200) {
// Tunnel connected! We're finished \o/ #WinningAtLife #DealWithIt
stream_context_set_option($struct->socket, 'artax*', 'is_tunneled', true);
$struct->promisor->succeed($struct->socket);
\Amp\cancel($struct->readWatcher);
} else {
$struct->promisor->fail(new ClientException(sprintf('Unexpected response status received from proxy: %d', $status)));
\Amp\cancel($struct->readWatcher);
}
} catch (ParseException $e) {
\Amp\cancel($struct->readWatcher);
$struct->promisor->fail(new ClientException('Invalid HTTP response received from proxy while establishing tunnel', 0, $e));
}
}