feat: update VPN connection to parse URL and ensure HTTPS prefix

This commit is contained in:
Kevin Yue committed 2025-07-08 23:26:04 +08:00
1 parent 1d3aa889d5
commit e1eb9e20f1
3 files changed
+12 -6

No files matched your search

+1 -1
View File
@@ -122,7 +122,7 @@ impl Cli {
let browser = self
.browser
.as_deref()
.or_else(|| self.default_browser.then(|| "default"));
.or_else(|| self.default_browser.then_some("default"));
#[cfg(not(feature = "webview-auth"))]
let browser = self.browser.as_deref().or(Some("default"));
+1 -1
View File
@@ -77,7 +77,7 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
openconnect_set_loglevel(vpninfo, PRG_TRACE);
openconnect_init_ssl();
openconnect_set_protocol(vpninfo, "gp");
openconnect_set_hostname(vpninfo, options->server);
openconnect_parse_url(vpninfo, options->server);
openconnect_set_cookie(vpninfo, options->cookie);
if (options->os) {
+10 -4
View File
@@ -36,7 +36,13 @@ pub struct Vpn {
impl Vpn {
pub fn builder(server: &str, cookie: &str) -> VpnBuilder {
VpnBuilder::new(server, cookie)
// prepend "https://" to the server if it doesn't already start with it
let server = if server.starts_with("https://") {
server.to_string()
} else {
format!("https://{}", server)
};
VpnBuilder::new(server, cookie.to_string())
}
pub fn connect(&self, on_connected: impl FnOnce() + 'static + Send + Sync) -> i32 {
@@ -134,10 +140,10 @@ pub struct VpnBuilder {
}
impl VpnBuilder {
fn new(server: &str, cookie: &str) -> Self {
fn new(server: String, cookie: String) -> Self {
Self {
server: server.to_string(),
cookie: cookie.to_string(),
server,
cookie,
script: None,
interface: None,