WebSocketContext.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #region License
  2. /*
  3. * WebSocketContext.cs
  4. *
  5. * The MIT License
  6. *
  7. * Copyright (c) 2012-2022 sta.blockhead
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. */
  27. #endregion
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Collections.Specialized;
  31. using System.Security.Principal;
  32. namespace WebSocketSharp.Net.WebSockets
  33. {
  34. /// <summary>
  35. /// Exposes the access to the information in a WebSocket handshake request.
  36. /// </summary>
  37. /// <remarks>
  38. /// This class is an abstract class.
  39. /// </remarks>
  40. public abstract class WebSocketContext
  41. {
  42. #region Protected Constructors
  43. /// <summary>
  44. /// Initializes a new instance of the <see cref="WebSocketContext"/> class.
  45. /// </summary>
  46. protected WebSocketContext ()
  47. {
  48. }
  49. #endregion
  50. #region Public Properties
  51. /// <summary>
  52. /// Gets the HTTP cookies included in the handshake request.
  53. /// </summary>
  54. /// <value>
  55. /// A <see cref="WebSocketSharp.Net.CookieCollection"/> that contains
  56. /// the cookies.
  57. /// </value>
  58. public abstract CookieCollection CookieCollection { get; }
  59. /// <summary>
  60. /// Gets the HTTP headers included in the handshake request.
  61. /// </summary>
  62. /// <value>
  63. /// A <see cref="NameValueCollection"/> that contains the headers.
  64. /// </value>
  65. public abstract NameValueCollection Headers { get; }
  66. /// <summary>
  67. /// Gets the value of the Host header included in the handshake request.
  68. /// </summary>
  69. /// <value>
  70. /// A <see cref="string"/> that represents the server host name requested
  71. /// by the client.
  72. /// </value>
  73. public abstract string Host { get; }
  74. /// <summary>
  75. /// Gets a value indicating whether the client is authenticated.
  76. /// </summary>
  77. /// <value>
  78. /// <c>true</c> if the client is authenticated; otherwise, <c>false</c>.
  79. /// </value>
  80. public abstract bool IsAuthenticated { get; }
  81. /// <summary>
  82. /// Gets a value indicating whether the handshake request is sent from
  83. /// the local computer.
  84. /// </summary>
  85. /// <value>
  86. /// <c>true</c> if the handshake request is sent from the same computer
  87. /// as the server; otherwise, <c>false</c>.
  88. /// </value>
  89. public abstract bool IsLocal { get; }
  90. /// <summary>
  91. /// Gets a value indicating whether a secure connection is used to send
  92. /// the handshake request.
  93. /// </summary>
  94. /// <value>
  95. /// <c>true</c> if the connection is secure; otherwise, <c>false</c>.
  96. /// </value>
  97. public abstract bool IsSecureConnection { get; }
  98. /// <summary>
  99. /// Gets a value indicating whether the request is a WebSocket handshake
  100. /// request.
  101. /// </summary>
  102. /// <value>
  103. /// <c>true</c> if the request is a WebSocket handshake request; otherwise,
  104. /// <c>false</c>.
  105. /// </value>
  106. public abstract bool IsWebSocketRequest { get; }
  107. /// <summary>
  108. /// Gets the value of the Origin header included in the handshake request.
  109. /// </summary>
  110. /// <value>
  111. /// A <see cref="string"/> that represents the value of the Origin header.
  112. /// </value>
  113. public abstract string Origin { get; }
  114. /// <summary>
  115. /// Gets the query string included in the handshake request.
  116. /// </summary>
  117. /// <value>
  118. /// A <see cref="NameValueCollection"/> that contains the query parameters.
  119. /// </value>
  120. public abstract NameValueCollection QueryString { get; }
  121. /// <summary>
  122. /// Gets the URI requested by the client.
  123. /// </summary>
  124. /// <value>
  125. /// A <see cref="Uri"/> that represents the URI parsed from the request.
  126. /// </value>
  127. public abstract Uri RequestUri { get; }
  128. /// <summary>
  129. /// Gets the value of the Sec-WebSocket-Key header included in
  130. /// the handshake request.
  131. /// </summary>
  132. /// <value>
  133. /// <para>
  134. /// A <see cref="string"/> that represents the value of
  135. /// the Sec-WebSocket-Key header.
  136. /// </para>
  137. /// <para>
  138. /// The value is used to prove that the server received
  139. /// a valid WebSocket handshake request.
  140. /// </para>
  141. /// </value>
  142. public abstract string SecWebSocketKey { get; }
  143. /// <summary>
  144. /// Gets the names of the subprotocols from the Sec-WebSocket-Protocol
  145. /// header included in the handshake request.
  146. /// </summary>
  147. /// <value>
  148. /// <para>
  149. /// An <see cref="T:System.Collections.Generic.IEnumerable{string}"/>
  150. /// instance.
  151. /// </para>
  152. /// <para>
  153. /// It provides an enumerator which supports the iteration over
  154. /// the collection of the names of the subprotocols.
  155. /// </para>
  156. /// </value>
  157. public abstract IEnumerable<string> SecWebSocketProtocols { get; }
  158. /// <summary>
  159. /// Gets the value of the Sec-WebSocket-Version header included in
  160. /// the handshake request.
  161. /// </summary>
  162. /// <value>
  163. /// A <see cref="string"/> that represents the WebSocket protocol
  164. /// version specified by the client.
  165. /// </value>
  166. public abstract string SecWebSocketVersion { get; }
  167. /// <summary>
  168. /// Gets the endpoint to which the handshake request is sent.
  169. /// </summary>
  170. /// <value>
  171. /// A <see cref="System.Net.IPEndPoint"/> that represents the server
  172. /// IP address and port number.
  173. /// </value>
  174. public abstract System.Net.IPEndPoint ServerEndPoint { get; }
  175. /// <summary>
  176. /// Gets the client information.
  177. /// </summary>
  178. /// <value>
  179. /// A <see cref="IPrincipal"/> instance that represents identity,
  180. /// authentication, and security roles for the client.
  181. /// </value>
  182. public abstract IPrincipal User { get; }
  183. /// <summary>
  184. /// Gets the endpoint from which the handshake request is sent.
  185. /// </summary>
  186. /// <value>
  187. /// A <see cref="System.Net.IPEndPoint"/> that represents the client
  188. /// IP address and port number.
  189. /// </value>
  190. public abstract System.Net.IPEndPoint UserEndPoint { get; }
  191. /// <summary>
  192. /// Gets the WebSocket interface used for two-way communication between
  193. /// the client and server.
  194. /// </summary>
  195. /// <value>
  196. /// A <see cref="WebSocketSharp.WebSocket"/> that represents the interface.
  197. /// </value>
  198. public abstract WebSocket WebSocket { get; }
  199. #endregion
  200. }
  201. }