function allowInsecureConnection(request, options) {
    if (options.allowInsecureConnection && request.allowInsecureConnection) {
        const url = new URL(request.url);
        if (url.hostname === "localhost" || url.hostname === "127.0.0.1") {
            return true;
        }
    }
    return false;
}
Ensures that authentication is only allowed over HTTPS unless explicitly allowed.
Throws an error if the connection is not secure and not explicitly allowed.