public function handleData($data)
{
$this->buffer .= $data;
if (false !== strpos($this->buffer, "\r\n\r\n")) {
list($response, $bodyChunk) = $this->parseResponse($this->buffer);
$this->buffer = null;
$this->stream->removeListener('drain', array($this, 'handleDrain'));
$this->stream->removeListener('data', array($this, 'handleData'));
$this->stream->removeListener('end', array($this, 'handleEnd'));
$this->stream->removeListener('error', array($this, 'handleError'));
$this->response = $response;
$response->on('end', function () {
$this->close();
});
$response->on('error', function (\Exception $error) {
$this->closeError(new \RuntimeException("An error occured in the response", 0, $error));
});
$this->emit('response', array($response, $this));
$this->stream->emit('data', array($bodyChunk));
}
}