http urls monitor.

doc.go 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package websocket implements the WebSocket protocol defined in RFC 6455.
  5. //
  6. // Overview
  7. //
  8. // The Conn type represents a WebSocket connection. A server application calls
  9. // the Upgrader.Upgrade method from an HTTP request handler to get a *Conn:
  10. //
  11. // var upgrader = websocket.Upgrader{
  12. // ReadBufferSize: 1024,
  13. // WriteBufferSize: 1024,
  14. // }
  15. //
  16. // func handler(w http.ResponseWriter, r *http.Request) {
  17. // conn, err := upgrader.Upgrade(w, r, nil)
  18. // if err != nil {
  19. // log.Println(err)
  20. // return
  21. // }
  22. // ... Use conn to send and receive messages.
  23. // }
  24. //
  25. // Call the connection's WriteMessage and ReadMessage methods to send and
  26. // receive messages as a slice of bytes. This snippet of code shows how to echo
  27. // messages using these methods:
  28. //
  29. // for {
  30. // messageType, p, err := conn.ReadMessage()
  31. // if err != nil {
  32. // log.Println(err)
  33. // return
  34. // }
  35. // if err := conn.WriteMessage(messageType, p); err != nil {
  36. // log.Println(err)
  37. // return
  38. // }
  39. // }
  40. //
  41. // In above snippet of code, p is a []byte and messageType is an int with value
  42. // websocket.BinaryMessage or websocket.TextMessage.
  43. //
  44. // An application can also send and receive messages using the io.WriteCloser
  45. // and io.Reader interfaces. To send a message, call the connection NextWriter
  46. // method to get an io.WriteCloser, write the message to the writer and close
  47. // the writer when done. To receive a message, call the connection NextReader
  48. // method to get an io.Reader and read until io.EOF is returned. This snippet
  49. // shows how to echo messages using the NextWriter and NextReader methods:
  50. //
  51. // for {
  52. // messageType, r, err := conn.NextReader()
  53. // if err != nil {
  54. // return
  55. // }
  56. // w, err := conn.NextWriter(messageType)
  57. // if err != nil {
  58. // return err
  59. // }
  60. // if _, err := io.Copy(w, r); err != nil {
  61. // return err
  62. // }
  63. // if err := w.Close(); err != nil {
  64. // return err
  65. // }
  66. // }
  67. //
  68. // Data Messages
  69. //
  70. // The WebSocket protocol distinguishes between text and binary data messages.
  71. // Text messages are interpreted as UTF-8 encoded text. The interpretation of
  72. // binary messages is left to the application.
  73. //
  74. // This package uses the TextMessage and BinaryMessage integer constants to
  75. // identify the two data message types. The ReadMessage and NextReader methods
  76. // return the type of the received message. The messageType argument to the
  77. // WriteMessage and NextWriter methods specifies the type of a sent message.
  78. //
  79. // It is the application's responsibility to ensure that text messages are
  80. // valid UTF-8 encoded text.
  81. //
  82. // Control Messages
  83. //
  84. // The WebSocket protocol defines three types of control messages: close, ping
  85. // and pong. Call the connection WriteControl, WriteMessage or NextWriter
  86. // methods to send a control message to the peer.
  87. //
  88. // Connections handle received close messages by calling the handler function
  89. // set with the SetCloseHandler method and by returning a *CloseError from the
  90. // NextReader, ReadMessage or the message Read method. The default close
  91. // handler sends a close message to the peer.
  92. //
  93. // Connections handle received ping messages by calling the handler function
  94. // set with the SetPingHandler method. The default ping handler sends a pong
  95. // message to the peer.
  96. //
  97. // Connections handle received pong messages by calling the handler function
  98. // set with the SetPongHandler method. The default pong handler does nothing.
  99. // If an application sends ping messages, then the application should set a
  100. // pong handler to receive the corresponding pong.
  101. //
  102. // The control message handler functions are called from the NextReader,
  103. // ReadMessage and message reader Read methods. The default close and ping
  104. // handlers can block these methods for a short time when the handler writes to
  105. // the connection.
  106. //
  107. // The application must read the connection to process close, ping and pong
  108. // messages sent from the peer. If the application is not otherwise interested
  109. // in messages from the peer, then the application should start a goroutine to
  110. // read and discard messages from the peer. A simple example is:
  111. //
  112. // func readLoop(c *websocket.Conn) {
  113. // for {
  114. // if _, _, err := c.NextReader(); err != nil {
  115. // c.Close()
  116. // break
  117. // }
  118. // }
  119. // }
  120. //
  121. // Concurrency
  122. //
  123. // Connections support one concurrent reader and one concurrent writer.
  124. //
  125. // Applications are responsible for ensuring that no more than one goroutine
  126. // calls the write methods (NextWriter, SetWriteDeadline, WriteMessage,
  127. // WriteJSON, EnableWriteCompression, SetCompressionLevel) concurrently and
  128. // that no more than one goroutine calls the read methods (NextReader,
  129. // SetReadDeadline, ReadMessage, ReadJSON, SetPongHandler, SetPingHandler)
  130. // concurrently.
  131. //
  132. // The Close and WriteControl methods can be called concurrently with all other
  133. // methods.
  134. //
  135. // Origin Considerations
  136. //
  137. // Web browsers allow Javascript applications to open a WebSocket connection to
  138. // any host. It's up to the server to enforce an origin policy using the Origin
  139. // request header sent by the browser.
  140. //
  141. // The Upgrader calls the function specified in the CheckOrigin field to check
  142. // the origin. If the CheckOrigin function returns false, then the Upgrade
  143. // method fails the WebSocket handshake with HTTP status 403.
  144. //
  145. // If the CheckOrigin field is nil, then the Upgrader uses a safe default: fail
  146. // the handshake if the Origin request header is present and the Origin host is
  147. // not equal to the Host request header.
  148. //
  149. // The deprecated package-level Upgrade function does not perform origin
  150. // checking. The application is responsible for checking the Origin header
  151. // before calling the Upgrade function.
  152. //
  153. // Compression EXPERIMENTAL
  154. //
  155. // Per message compression extensions (RFC 7692) are experimentally supported
  156. // by this package in a limited capacity. Setting the EnableCompression option
  157. // to true in Dialer or Upgrader will attempt to negotiate per message deflate
  158. // support.
  159. //
  160. // var upgrader = websocket.Upgrader{
  161. // EnableCompression: true,
  162. // }
  163. //
  164. // If compression was successfully negotiated with the connection's peer, any
  165. // message received in compressed form will be automatically decompressed.
  166. // All Read methods will return uncompressed bytes.
  167. //
  168. // Per message compression of messages written to a connection can be enabled
  169. // or disabled by calling the corresponding Conn method:
  170. //
  171. // conn.EnableWriteCompression(false)
  172. //
  173. // Currently this package does not support compression with "context takeover".
  174. // This means that messages must be compressed and decompressed in isolation,
  175. // without retaining sliding window or dictionary state across messages. For
  176. // more details refer to RFC 7692.
  177. //
  178. // Use of compression is experimental and may result in decreased performance.
  179. package websocket