Invalid multibyte sequences in request URL causes errors

Rebased from #7411