diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-05-10 11:53:08 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-05-10 11:53:08 +0200 |
| commit | 9e3e7f22892c3504e6de9827af0fabd9b4b098ea (patch) | |
| tree | 0d16b63dae17f73bccfe720d9c03c25166856497 /internal/api.go | |
| parent | 113de64ac73f529af14da3e0aff12b05c2edd3a7 (diff) | |
API/Server: Correctly handle multiple protocol preference
Diffstat (limited to 'internal/api.go')
| -rw-r--r-- | internal/api.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/internal/api.go b/internal/api.go index b615976..45e025b 100644 --- a/internal/api.go +++ b/internal/api.go @@ -96,23 +96,33 @@ func APIInfo(server Server) error { return nil } -func APIConnectWireguard(server Server, profile_id string, pubkey string) (string, string, error) { +func APIConnectWireguard(server Server, profile_id string, pubkey string, supportsOpenVPN bool) (string, string, string, error) { headers := http.Header{ "content-type": {"application/x-www-form-urlencoded"}, "accept": {"application/x-wireguard-profile"}, } + if supportsOpenVPN { + headers.Add("accept", "application/x-openvpn-profile") + } + urlForm := url.Values{ "profile_id": {profile_id}, "public_key": {pubkey}, } header, connectBody, connectErr := apiAuthorizedRetry(server, http.MethodPost, "/connect", &HTTPOptionalParams{Headers: headers, Body: urlForm}) if connectErr != nil { - return "", "", &APIConnectWireguardError{Err: connectErr} + return "", "", "", &APIConnectWireguardError{Err: connectErr} } expires := header.Get("expires") - return string(connectBody), expires, nil + contentType := header.Get("content-type") + + content := "openvpn" + if contentType == "application/x-wireguard-profile" { + content = "wireguard" + } + return string(connectBody), content, expires, nil } func APIConnectOpenVPN(server Server, profile_id string) (string, string, error) { @@ -124,6 +134,7 @@ func APIConnectOpenVPN(server Server, profile_id string) (string, string, error) urlForm := url.Values{ "profile_id": {profile_id}, } + header, connectBody, connectErr := apiAuthorizedRetry(server, http.MethodPost, "/connect", &HTTPOptionalParams{Headers: headers, Body: urlForm}) if connectErr != nil { return "", "", &APIConnectOpenVPNError{Err: connectErr} |
