public async Task StartTunnel_Http()
        {
            // Setup - Create Tunnel
            var tunnelRequest = new StartTunnelRequest()
            {
                Name     = "Test_StartTunnel_Http",
                Protocol = "http",
                Address  = "1234"
            };
            var response = await Client.StartTunnelAsync(tunnelRequest);

            Assert.NotNull(response);
        }
Пример #2
0
        private async Task <Tunnel[]?> StartTunnelsAsync(string address, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(address))
            {
                address = "80";
            }
            else
            {
                if (!int.TryParse(address, out _))
                {
                    var url = new Uri(address);
                    if (url.Port != 80 && url.Port != 443)
                    {
                        address = $"{url.Host}:{url.Port}";
                    }
                    else
                    {
                        if (address.StartsWith("http://"))
                        {
                            address = address.Remove(address.IndexOf("http://"), "http://".Length);
                        }
                        if (address.StartsWith("https://"))
                        {
                            address = address.Remove(address.IndexOf("https://"), "https://".Length);
                        }
                    }
                }
            }

            // Start Tunnel
            var tunnel = await _client.StartTunnelAsync(new StartTunnelRequest()
            {
                Name       = System.AppDomain.CurrentDomain.FriendlyName,
                Address    = address,
                Protocol   = "http",
                HostHeader = address
            }, cancellationToken);

            // Get Tunnels
            var tunnels = (await _client.ListTunnelsAsync(cancellationToken))
                          .Where(t => t.Name == System.AppDomain.CurrentDomain.FriendlyName ||
                                 t.Name == $"{System.AppDomain.CurrentDomain.FriendlyName} (http)")
                          ?.ToArray();

            return(tunnels);
        }