moby / vpnkit

A toolkit for embedding VPN capabilities in your application
Apache License 2.0
1.1k stars 187 forks source link

Exposing a port should be idempotent and fix an ephemeral port leak #531

Closed djs55 closed 3 years ago

djs55 commented 3 years ago

Previously attempting to expose an existing port would return an error, which becomes an HTTP 500 internal server error.

This patch makes exposing a port idempotent, just like un-exposing a port already is.

Previously there was a port leak if the user requested any port (0) because we would store 0 in our map, and then look up the real port in Unexpose and fail to find it.

To make the API clearer, we switch to PUT and DELETE (instead of POST) but for backwards compatibility retain the POST handlers.

Minor additional updates: