using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Net; using System.Security.Principal; using System.Threading; using EmbedIO.Sessions; using EmbedIO.Utilities; namespace EmbedIO.WebSockets.Internal { internal sealed class WebSocketContext : IWebSocketContext { internal WebSocketContext( IHttpContextImpl httpContext, string webSocketVersion, IEnumerable requestedProtocols, string acceptedProtocol, IWebSocket webSocket, CancellationToken cancellationToken) { Id = UniqueIdGenerator.GetNext(); CancellationToken = cancellationToken; HttpContextId = httpContext.Id; Session = httpContext.Session; Items = httpContext.Items; LocalEndPoint = httpContext.LocalEndPoint; RemoteEndPoint = httpContext.RemoteEndPoint; RequestUri = httpContext.Request.Url; Headers = httpContext.Request.Headers; Origin = Headers[HttpHeaderNames.Origin]; RequestedProtocols = requestedProtocols; AcceptedProtocol = acceptedProtocol; WebSocketVersion = webSocketVersion; Cookies = httpContext.Request.Cookies; User = httpContext.User; IsAuthenticated = httpContext.User.Identity.IsAuthenticated; IsLocal = httpContext.Request.IsLocal; IsSecureConnection = httpContext.Request.IsSecureConnection; WebSocket = webSocket; } /// public string Id { get; } /// public CancellationToken CancellationToken { get; } /// public string HttpContextId { get; } /// public ISessionProxy Session { get; } /// public IDictionary Items { get; } /// public IPEndPoint LocalEndPoint { get; } /// public IPEndPoint RemoteEndPoint { get; } /// public Uri RequestUri { get; } /// public NameValueCollection Headers { get; } /// public string Origin { get; } /// public IEnumerable RequestedProtocols { get; } /// public string AcceptedProtocol { get; } /// public string WebSocketVersion { get; } /// public ICookieCollection Cookies { get; } /// public IPrincipal User { get; } /// public bool IsAuthenticated { get; } /// public bool IsLocal { get; } /// public bool IsSecureConnection { get; } /// public IWebSocket WebSocket { get; } } }