Cherry-pick fixes for HTTPS-Only mode

A cypherpunk sent some known HTTPS-Only issues that we could cherry-pick (they have not been uplifted upstream, though): #41050 (comment 2822085)