namespace IFramework.Net.WebSocket { internal class AccessInfo : BaseInfo { /// /// 连接主机 /// public string Host { get; set; } /// /// 连接源 /// public string Origin { get; set; } /// /// 安全扩展 /// public string SecWebSocketExtensions { get; set; } /// /// 安全密钥 /// public string SecWebSocketKey { get; set; } /// /// 安全版本 /// public string SecWebSocketVersion { get; set; } public override string ToString() { if (string.IsNullOrEmpty(HttpProto)) HttpProto = "GET / HTTP/1.1"; if (string.IsNullOrEmpty(SecWebSocketVersion)) SecWebSocketVersion = "13"; return string.Format("{0}{1}{2}{3}{4}{5}{6}", HttpProto + NewLine, "Host" + SplitChars + Host + NewLine, "Connection" + SplitChars + Connection + NewLine, "Upgrade" + SplitChars + Upgrade + NewLine, "Origin" + SplitChars + Origin + NewLine, "Sec-WebSocket-Version" + SplitChars + SecWebSocketVersion + NewLine, "Sec-WebSocket-Key" + SplitChars + SecWebSocketKey + NewLine + NewLine); } public bool IsHandShaked() { return string.IsNullOrEmpty(SecWebSocketKey) == false; } } internal class BaseInfo { /// /// http连接协议 /// public string HttpProto { get; set; } /// /// 连接类型 /// public string Connection { get; set; } /// /// 连接方式 /// public string Upgrade { get; set; } internal const string NewLine = "\r\n"; internal const string SplitChars = ": "; public BaseInfo() { Upgrade = "websocket"; Connection = "Upgrade"; } } }