1
wtt
2024-08-16 e03677790c63aba9379b84c976d172c3dcd0127a
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#region MIT License
/**
 * TcpListenerWebSocketContext.cs
 *
 * The MIT License
 *
 * Copyright (c) 2012 sta.blockhead
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#endregion
 
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Net.Sockets;
using System.Security.Principal;
 
namespace WebSocketSharp.Net.Sockets
{
 
    public class TcpListenerWebSocketContext : WebSocketContext
    {
        private TcpClient _client;
        private bool _isSecure;
        private RequestHandshake _request;
        private WebSocket _socket;
        private WsStream _stream;
 
        internal TcpListenerWebSocketContext(TcpClient client, bool secure)
        {
            _client = client;
            _isSecure = secure;
            _stream = WsStream.CreateServerStream(client, secure);
            _request = RequestHandshake.Parse(_stream.ReadHandshake());
            _socket = new WebSocket(this);
        }
 
        internal TcpClient Client
        {
            get
            {
                return _client;
            }
        }
 
        internal WsStream Stream
        {
            get
            {
                return _stream;
            }
        }
 
        public override CookieCollection CookieCollection
        {
            get
            {
                throw new NotImplementedException();
            }
        }
 
        public override NameValueCollection Headers
        {
            get
            {
                return _request.Headers;
            }
        }
 
        public override bool IsAuthenticated
        {
            get
            {
                throw new NotImplementedException();
            }
        }
 
        public override bool IsSecureConnection
        {
            get
            {
                return _isSecure;
            }
        }
 
        public override bool IsLocal
        {
            get
            {
                throw new NotImplementedException();
            }
        }
 
        public override string Origin
        {
            get
            {
                return Headers["Origin"];
            }
        }
 
        public virtual string Path
        {
            get
            {
                return Ext.GetAbsolutePath(_request.RequestUri);
            }
        }
 
        public override Uri RequestUri
        {
            get
            {
                return _request.RequestUri;
            }
        }
 
        public override string SecWebSocketKey
        {
            get
            {
                return Headers["Sec-WebSocket-Key"];
            }
        }
 
        public override IEnumerable<string> SecWebSocketProtocols
        {
            get
            {
                return Headers.GetValues("Sec-WebSocket-Protocol");
            }
        }
 
        public override string SecWebSocketVersion
        {
            get
            {
                return Headers["Sec-WebSocket-Version"];
            }
        }
 
        public virtual IPEndPoint ServerEndPoint
        {
            get
            {
                return (IPEndPoint)_client.Client.LocalEndPoint;
            }
        }
 
        public override IPrincipal User
        {
            get
            {
                throw new NotImplementedException();
            }
        }
 
        public virtual IPEndPoint UserEndPoint
        {
            get
            {
                return (IPEndPoint)_client.Client.RemoteEndPoint;
            }
        }
 
        public override WebSocket WebSocket
        {
            get
            {
                return _socket;
            }
        }
    }
}