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