Premature resolution of gateway to an ip address prevents connecting to some hosts ("Unexpected 404 result from server")
I've been unable to connect to a certain VPN network when using the NetworkManager plugin, while direct openconnect cli worked fine. I tracked this down to the plugin apparently resolving the gateway's hostname to an IP, then simply connecting directly to the IP via https. This drops the Hostname: header, which causes this particular server to reject the connection.
Specifically, changing nm-openconnect-service.c
:
/* The actual gateway to use (after redirection) comes from the auth
dialog, so it's in the secrets hash not the properties */
props_vpn_gw = nm_setting_vpn_get_secret (s_vpn, NM_OPENCONNECT_KEY_GATEWAY);
to
props_vpn_gw = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_GATEWAY);
In nm_openconnect_start_openconnect_binary resolves this problem, since it uses the user-entered gateway for the real connection. It's not apparent why using the resolved hostname for the connection is desirable, other than avoiding multiple lookups, so this change may be all that is needed.