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); }
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); }
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); }
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; }
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; }
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; }
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); }
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); }
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); }