public function request(
        $sourceMethod,
        $sourcePath,
        $targetPath,
        $sourceData = null,
        array $sourceHeaders = []
    ) {
        $this->sourceConnection = $this->sourceClient->getConnection(
            $sourceMethod,
            $sourcePath,
            $sourceData,
            $sourceHeaders
        );
        $sourceResponseHeaders = $this->sourceClient->getStreamHeaders();
        $body = '';

        if (empty($sourceResponseHeaders['status'])) {
            try {
                // Close the connection resource.
                fclose($this->sourceConnection);
            } catch (\Exception $e) {
            }
            throw HTTPException::readFailure(
                $this->sourceClient->getOptions()['ip'],
                $this->sourceClient->getOptions()['port'],
                'Received an empty response or not status code',
                0
            );
        } elseif ($sourceResponseHeaders['status'] != 200) {
            while (!feof($this->sourceConnection)) {
                $body .= fgets($this->sourceConnection);
            }
            try {
                fclose($this->sourceConnection);
            } catch (\Exception $e) {
            }

            return new ErrorResponse(
                $sourceResponseHeaders['status'],
                $sourceResponseHeaders,
                $body
            );
        } else {
            try {
                // Body is an array containing:
                // 1) Array of json string documents that don't have
                //  attachments. These should be posted using the Bulk API.
                // 2) Responses of posting docs with attachments.
                $body = $this->parseAndSend($targetPath);
                try {
                    fclose($this->sourceConnection);
                } catch (\Exception $e) {
                }

                return $body;
            } catch (\Exception $e) {
                throw $e;
            }
        }
    }