/// <summary> /// Initializes a new instance of the <see cref="WebConnection"/> class. /// </summary> /// <param name="tunnel">The tunnel this connection is associated with.</param> /// <param name="context">The context.</param> public WebConnection(WebTunnel tunnel, HttpContext context) : base(tunnel.Id) { _tunnel = tunnel; _context = context; _interceptor = new WebConnectionResponseInterceptor(context.Response); _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(context.RequestAborted); }
/// <summary> /// Creates a new web tunnel to the client. /// </summary> /// <param name="messageId">The message identifier.</param> /// <param name="domain">The domain to be used for the tunnel.</param> /// <returns> /// A <see cref="T:BlueBoxMoon.LocalSubway.Messages.Response" /> to be sent back to the client. /// </returns> protected override Task <Response> CreateWebTunnelAsync(Guid messageId, string domain) { var tunnel = new WebTunnel(this, domain); if (_domainManager.AddTunnel(tunnel)) { AddTunnel(tunnel); var url = $"https://{domain}.{_domainManager.Domain}"; var response = new Response(messageId, true, $"Tunnel created at {url}"); response.Values["tunnel_id"] = tunnel.Id; response.Values["url"] = url; return(Task.FromResult(response)); } else { return(Task.FromResult(new Response(messageId, false, $"Tunnel domain already in use."))); } }
/// <summary> /// Removes the tunnel. /// </summary> /// <param name="tunnel">The tunnel to be removed.</param> public void RemoveTunnel(WebTunnel tunnel) { _tunnels.TryRemove(tunnel.Subdomain, out var _); }
/// <summary> /// Attempts to add the tunnel. /// </summary> /// <param name="tunnel">The tunnel to be added.</param> /// <returns><c>true</c> if the tunnel was added or <c>false</c> if there was a subdomain name conflict.</returns> public bool AddTunnel(WebTunnel tunnel) { return(_tunnels.TryAdd(tunnel.Subdomain, tunnel)); }