AcceptInfo.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. namespace IFramework.Net.WebSocket
  2. {
  3. internal class AcceptInfo : BaseInfo
  4. {
  5. /// <summary>
  6. /// 接入访问验证码
  7. /// </summary>
  8. public string SecWebSocketAccept { get; set; }
  9. /// <summary>
  10. /// 客户端来源
  11. /// </summary>
  12. public string SecWebSocketLocation { get; set; }
  13. /// <summary>
  14. /// 服务端来源
  15. /// </summary>
  16. public string SecWebSocketOrigin { get; set; }
  17. public override string ToString()
  18. {
  19. if (string.IsNullOrEmpty(HttpProto))
  20. HttpProto = "HTTP/1.1 101 Switching Protocols";
  21. return string.Format("{0}{1}{2}{3}",
  22. HttpProto + NewLine,
  23. "Connection" + SplitChars + Connection + NewLine,
  24. "Upgrade" + SplitChars + Upgrade + NewLine,
  25. "Sec-WebSocket-Accept" + SplitChars + SecWebSocketAccept + NewLine + NewLine//很重要,需要两个newline
  26. );
  27. }
  28. public bool IsHandShaked()
  29. {
  30. return string.IsNullOrEmpty(SecWebSocketAccept) == false;
  31. }
  32. }
  33. }