public function request($method, $path, $data = null, $raw = false, array $headers = [])
    {
        $fullPath = $path;
        if ($this->options['path']) {
            $fullPath = '/'.$this->options['path'].$path;
        }

        $this->checkConnection($method, $fullPath, $data, $headers);

        // Read request body.
        $body = '';
        while (!feof($this->httpFilePointer)) {
            $body .= fgets($this->httpFilePointer);
        }

        $headers = $this->getStreamHeaders();

        if (empty($headers['status'])) {
            throw HTTPException::readFailure(
                $this->options['ip'],
                $this->options['port'],
                'Received an empty response or not status code',
                0
            );
        }

        // Create response object from couch db response.
        if ($headers['status'] >= 400) {
            return new ErrorResponse($headers['status'], $headers, $body);
        }

        return new Response($headers['status'], $headers, $body, $raw);
    }