summaryrefslogtreecommitdiff
path: root/internal/server/api.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-10-04 14:53:58 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-10-04 14:53:58 +0200
commit762a034cc1af55d09dc0a174947356e36bf15569 (patch)
tree4c29d0ebd131a919accc944599d3c10ba61b09d2 /internal/server/api.go
parent0096d0471fef972e305a61435623d64b7da4f0d9 (diff)
Server: Implement `prefer_tcp` according to spec
Diffstat (limited to 'internal/server/api.go')
-rw-r--r--internal/server/api.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/internal/server/api.go b/internal/server/api.go
index 4648a8f..0c1a0f5 100644
--- a/internal/server/api.go
+++ b/internal/server/api.go
@@ -131,10 +131,19 @@ func APIInfo(server Server) error {
return nil
}
+// see https://github.com/eduvpn/documentation/blob/v3/API.md#request-1
+func GetPreferTCPString(preferTCP bool) string {
+ if preferTCP {
+ return "yes"
+ }
+ return "no"
+}
+
func APIConnectWireguard(
server Server,
profile_id string,
pubkey string,
+ preferTCP bool,
supportsOpenVPN bool,
) (string, string, time.Time, error) {
errorMessage := "failed obtaining a WireGuard configuration"
@@ -143,6 +152,8 @@ func APIConnectWireguard(
"accept": {"application/x-wireguard-profile"},
}
+ // This profile also supports OpenVPN
+ // Indicate that we also accept OpenVPN profiles
if supportsOpenVPN {
headers.Add("accept", "application/x-openvpn-profile")
}
@@ -150,6 +161,7 @@ func APIConnectWireguard(
urlForm := url.Values{
"profile_id": {profile_id},
"public_key": {pubkey},
+ "prefer_tcp": {GetPreferTCPString(preferTCP)},
}
header, connectBody, connectErr := apiAuthorizedRetry(
server,
@@ -180,7 +192,7 @@ func APIConnectWireguard(
return string(connectBody), content, pTime, nil
}
-func APIConnectOpenVPN(server Server, profile_id string) (string, time.Time, error) {
+func APIConnectOpenVPN(server Server, profile_id string, preferTCP bool) (string, time.Time, error) {
errorMessage := "failed obtaining an OpenVPN configuration"
headers := http.Header{
"content-type": {"application/x-www-form-urlencoded"},
@@ -189,6 +201,7 @@ func APIConnectOpenVPN(server Server, profile_id string) (string, time.Time, err
urlForm := url.Values{
"profile_id": {profile_id},
+ "prefer_tcp": {GetPreferTCPString(preferTCP)},
}
header, connectBody, connectErr := apiAuthorizedRetry(