private void ParseResponseHeader(Reactor.Buffer buffer) { var data = buffer.ToString("utf8"); string [] split = data.Split(new string [] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); try { var http = split[0]; var s1 = http.Split(new char[] { ' ' }); this.StatusCode = int.Parse(s1[1]); for (var i = 1; i < split.Length; i++) { var s2 = split[i].Split(new char[] { ':' }); this.Headers[s2[0]] = s2[1]; } } catch { } }
private void ParseResponseBody(Reactor.Buffer buffer) { try { //--------------------------------------------- // checking the body of the response. The goal // here is to extract any frames passed on the // request from the server, as is the case with // socket.io. //--------------------------------------------- var data = buffer.ToString("utf8"); if (data.Contains("\r\n")) { var split = data.Split(new string[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries); if (split.Length == 2) { var bytes = buffer.ToArray(); //--------------------------------------------- // scan for frames //--------------------------------------------- var framedatalist = new List <List <byte> >(); List <byte> framedata = null; foreach (var b in bytes) { if (b == 0x81) { framedata = new List <byte>(); framedatalist.Add(framedata); } if (framedata != null) { framedata.Add(b); } } //--------------------------------------------- // add frame to frame list. //--------------------------------------------- foreach (var item in framedatalist) { var frame = Reactor.Web.Socket.Protocol.Frame.Parse(item.ToArray(), true); this.Frames.Add(frame); } } } } catch { } }
internal WebSocketResponse(Reactor.Tcp.Socket socket, Reactor.Buffer buffer) { this.Socket = socket; this.Frames = new List <Frame>(); this.Headers = new Dictionary <string, string>(); this.ParseResponseHeader(buffer); this.ParseResponseBody(buffer); }