コード例 #1
0
        public void CreateHandler(IEnumerable <byte> data)
        {
            var request = _parseRequest(data.ToArray());

            if (request == null)
            {
                return;
            }

            Handler = _handlerFactory(request);
            if (Handler == null)
            {
                return;
            }

            var subProtocol = _negotiateSubProtocol(request.SubProtocols);

            ConnectionInfo = WebSocketConnectionInfo.Create(request, Socket.RemoteIpAddress, Socket.RemotePort, subProtocol);

            _initialize(this);

            var handshake = Handler.CreateHandshake(subProtocol);

            Send(handshake, "handshake", OnOpen);
        }
コード例 #2
0
        public static WebSocketConnectionInfo Create(WebSocketHttpRequest request, string clientIp, int clientPort)
        {
            var info = new WebSocketConnectionInfo
            {
                Origin          = request["Origin"] ?? request["Sec-WebSocket-Origin"],
                Host            = request["Host"],
                SubProtocol     = request["Sec-WebSocket-Protocol"],
                Path            = request.Path,
                ClientIpAddress = clientIp,
                ClientPort      = clientPort
            };
            var cookieHeader = request["Cookie"];

            if (cookieHeader != null)
            {
                var match  = CookieRegex.Match(cookieHeader);
                var fields = match.Groups["cookie_name"].Captures;
                var values = match.Groups["cookie_value"].Captures;
                for (var i = 0; i < fields.Count; i++)
                {
                    var name  = fields[i].ToString();
                    var value = values[i].ToString();
                    info.Cookies[name] = value;
                }
            }

            return(info);
        }
コード例 #3
0
        public static WebSocketConnectionInfo Create(WebSocketHttpRequest request, string clientIp, int clientPort, string negotiatedSubprotocol)
        {
            var info = new WebSocketConnectionInfo
            {
                Origin                = request["Origin"] ?? request["Sec-WebSocket-Origin"],
                Host                  = request["Host"],
                SubProtocol           = request["Sec-WebSocket-Protocol"],
                Path                  = request.Path,
                ClientIpAddress       = clientIp,
                ClientPort            = clientPort,
                NegotiatedSubProtocol = negotiatedSubprotocol,
                Headers               = new Dictionary <string, string>(request.Headers, System.StringComparer.InvariantCultureIgnoreCase)
            };
            var cookieHeader = request["Cookie"];

            if (cookieHeader != null)
            {
                var match  = CookieRegex.Match(cookieHeader);
                var fields = match.Groups["cookie_name"].Captures;
                var values = match.Groups["cookie_value"].Captures;
                for (var i = 0; i < fields.Count; i++)
                {
                    var name  = fields[i].ToString();
                    var value = values[i].ToString();
                    info.Cookies[name] = value;
                }
            }

            return(info);
        }
コード例 #4
0
        public static WebSocketConnectionInfo Create(WebSocketHttpRequest request, string clientIp, int clientPort, string negotiatedSubprotocol)
        {
            var info = new WebSocketConnectionInfo
                           {
                               Origin = request["Origin"] ?? request["Sec-WebSocket-Origin"],
                               Host = request["Host"],
                               SubProtocol = request["Sec-WebSocket-Protocol"],
                               Path = request.Path,
                               ClientIpAddress = clientIp,
                               ClientPort = clientPort,
                               NegotiatedSubProtocol = negotiatedSubprotocol,
                               Headers = new Dictionary<string, string>(request.Headers, System.StringComparer.InvariantCultureIgnoreCase)
                           };
            var cookieHeader = request["Cookie"];

            if (cookieHeader != null)
            {
                var match = CookieRegex.Match(cookieHeader);
                var fields = match.Groups["cookie_name"].Captures;
                var values = match.Groups["cookie_value"].Captures;
                for (var i = 0; i < fields.Count; i++)
                {
                    var name = fields[i].ToString();
                    var value = values[i].ToString();
                    info.Cookies[name] = value;
                }
            }

            return info;
        }
コード例 #5
0
        public static WebSocketConnectionInfo Create(WebSocketHttpRequest request, string clientIp, int clientPort, string negotiatedSubprotocol)
        {
            var info = new WebSocketConnectionInfo
                           {
                               Origin = request["Origin"] ?? request["Sec-WebSocket-Origin"],
                               Host = request["Host"],
                               SubProtocol = request["Sec-WebSocket-Protocol"],
                               Path = request.Path,
                               ClientIpAddress = clientIp,
                               ClientPort = clientPort,
                               NegotiatedSubProtocol = negotiatedSubprotocol
                           };

            var cookieHeader = request["Cookie"];
            if (cookieHeader != null)
            {
                var cookies = cookieHeader.Split(';');
                foreach (var cookie in cookies)
                {
                    var parts = cookie.Split('=');
                    if (parts.Length == 2)
                        info.Cookies.Add(parts[0], parts[1]);
                }
            }

            return info;
        }
コード例 #6
0
        public static WebSocketConnectionInfo Create(WebSocketHttpRequest request, string clientIp)
        {
            var info = new WebSocketConnectionInfo
                           {
                               Origin = request["Origin"] ?? request["Sec-WebSocket-Origin"],
                               Host = request["Host"],
                               SubProtocol = request["Sec-WebSocket-Protocol"],
                               Path = request.Path,
                               ClientIpAddress = clientIp
                           };
            var cookieHeader = request["Cookie"];

            if (cookieHeader != null)
            {
                var match = CookieRegex.Match(cookieHeader);
                var fields = match.Groups["cookie_name"].Captures;
                var values = match.Groups["cookie_value"].Captures;
                for (var i = 0; i < fields.Count; i++)
                {
                    var name = fields[i].ToString();
                    var value = values[i].ToString();
                    info.Cookies[name] = value;
                }
            }

            return info;
        }
コード例 #7
0
ファイル: WebSocketConnection.cs プロジェクト: mdsitton/Fleck
        public bool CreateHandler(ArraySegment <byte> data)
        {
            var request = _parseRequest(data);

            if (request == null)
            {
                return(false);
            }

            Handler = _handlerFactory(this, request);
            if (Handler == null)
            {
                return(false);
            }

            ConnectionInfo = WebSocketConnectionInfo.Create(request, Socket.RemoteIpAddress, Socket.RemotePort);

            _initialize(this);

            var handshake = Handler.CreateHandshake();

            SendBytes(handshake, (instance, success) =>
            {
                if (success)
                {
                    instance.OnOpen();
                }
            });

            return(true);
        }
コード例 #8
0
        public static WebSocketConnectionInfo Create(WebSocketHttpRequest request, string clientIp, int clientPort, string negotiatedSubprotocol)
        {
            var info = new WebSocketConnectionInfo
                           {
                               Origin = request["Origin"] ?? request["Sec-WebSocket-Origin"],
                               Host = request["Host"],
                               SubProtocol = request["Sec-WebSocket-Protocol"],
                               Path = request.Path,
                               ClientIpAddress = clientIp,
                               ClientPort = clientPort,
                               NegotiatedSubProtocol = negotiatedSubprotocol
                           };

            var cookieHeader = request["Cookie"];
            if (cookieHeader != null)
            {
                var cookies = cookieHeader.Split(';');
                foreach (var cookie in cookies)
                {
                    var parts = cookie.Split('=');
                    if (parts.Length == 2)
                        info.Cookies.Add(parts[0], parts[1]);
                }
            }

            return info;
        }
コード例 #9
0
        public static WebSocketConnectionInfo Create(WebSocketHttpRequest request, IPAddress clientIp, int clientPort)
        {
            var info = new WebSocketConnectionInfo
            {
                Origin          = request["Origin"] ?? request["Sec-WebSocket-Origin"],
                Host            = request["Host"],
                SubProtocol     = request["Sec-WebSocket-Protocol"],
                Path            = request.Path,
                ClientIpAddress = clientIp,
                ClientPort      = clientPort,
            };

            return(info);
        }
コード例 #10
0
        public void CreateHandler(IEnumerable <byte> data)
        {
            var request = _parseRequest(data.ToArray());

            if (request == null)
            {
                return;
            }
            Handler = _handlerFactory(request);
            if (Handler == null)
            {
                return;
            }
            ConnectionInfo = WebSocketConnectionInfo.Create(request, Socket.RemoteIpAddress, Socket.RemotePort);

            _initialize(this);

            var handshake = Handler.CreateHandshake();

            SendBytes(handshake, OnOpen);
        }