Detect when protocol changes and invalidate session to get a new cookie with secure flag set according. It fixes #3714