WithSubProtocol 根据请求头和预期的子协议列表设置子协议 Sets the subprotocol based on the request header and the expected subprotocols list
(requestHeader http.Header, expectedSubProtocols []string)
| 65 | // WithSubProtocol 根据请求头和预期的子协议列表设置子协议 |
| 66 | // Sets the subprotocol based on the request header and the expected subprotocols list |
| 67 | func (c *responseWriter) WithSubProtocol(requestHeader http.Header, expectedSubProtocols []string) { |
| 68 | if len(expectedSubProtocols) > 0 { |
| 69 | c.subprotocol = internal.GetIntersectionElem(expectedSubProtocols, internal.Split(requestHeader.Get(internal.SecWebSocketProtocol.Key), ",")) |
| 70 | if c.subprotocol == "" { |
| 71 | c.err = ErrSubprotocolNegotiation |
| 72 | return |
| 73 | } |
| 74 | c.WithHeader(internal.SecWebSocketProtocol.Key, c.subprotocol) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // Write 将缓冲区内容写入连接,并设置超时 |
| 79 | // Writes the buffer content to the connection and sets the timeout |
no test coverage detected