aboutsummaryrefslogtreecommitdiff
path: root/SocketHttpListener/Net/WebSockets/HttpListenerWebSocketContext.cs
blob: 5ed49ec47d683b745d293a0b490a29d07aceae25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using System.Net;
using System.Security.Principal;
using MediaBrowser.Model.Services;

namespace SocketHttpListener.Net.WebSockets
{
    public class HttpListenerWebSocketContext : WebSocketContext
    {
        private readonly Uri _requestUri;
        private readonly QueryParamCollection _headers;
        private readonly CookieCollection _cookieCollection;
        private readonly IPrincipal _user;
        private readonly bool _isAuthenticated;
        private readonly bool _isLocal;
        private readonly bool _isSecureConnection;

        private readonly string _origin;
        private readonly IEnumerable<string> _secWebSocketProtocols;
        private readonly string _secWebSocketVersion;
        private readonly string _secWebSocketKey;

        private readonly WebSocket _webSocket;

        internal HttpListenerWebSocketContext(
            Uri requestUri,
            QueryParamCollection headers,
            CookieCollection cookieCollection,
            IPrincipal user,
            bool isAuthenticated,
            bool isLocal,
            bool isSecureConnection,
            string origin,
            IEnumerable<string> secWebSocketProtocols,
            string secWebSocketVersion,
            string secWebSocketKey,
            WebSocket webSocket)
        {
            _cookieCollection = new CookieCollection();
            _cookieCollection.Add(cookieCollection);

            //_headers = new NameValueCollection(headers);
            _headers = headers;
            _user = CopyPrincipal(user);

            _requestUri = requestUri;
            _isAuthenticated = isAuthenticated;
            _isLocal = isLocal;
            _isSecureConnection = isSecureConnection;
            _origin = origin;
            _secWebSocketProtocols = secWebSocketProtocols;
            _secWebSocketVersion = secWebSocketVersion;
            _secWebSocketKey = secWebSocketKey;
            _webSocket = webSocket;
        }

        public override Uri RequestUri => _requestUri;

        public override QueryParamCollection Headers => _headers;

        public override string Origin => _origin;

        public override IEnumerable<string> SecWebSocketProtocols => _secWebSocketProtocols;

        public override string SecWebSocketVersion => _secWebSocketVersion;

        public override string SecWebSocketKey => _secWebSocketKey;

        public override CookieCollection CookieCollection => _cookieCollection;

        public override IPrincipal User => _user;

        public override bool IsAuthenticated => _isAuthenticated;

        public override bool IsLocal => _isLocal;

        public override bool IsSecureConnection => _isSecureConnection;

        public override WebSocket WebSocket => _webSocket;

        private static IPrincipal CopyPrincipal(IPrincipal user)
        {
            if (user != null)
            {
                throw new NotImplementedException();
            }

            return null;
        }
    }
}