private function assignRedirectRefererHeader(Request $request, string $refererUri, string $newUri): Request {
        $refererIsEncrypted = (\stripos($refererUri, 'https') === 0);
        $destinationIsEncrypted = (\stripos($newUri, 'https') === 0);

        if (!$refererIsEncrypted || $destinationIsEncrypted) {
            return $request->withHeader('Referer', $refererUri);
        }

        return $request->withoutHeader('Referer');
    }