MCPcopy
hub / github.com/lxzan/gws / WithSubProtocol

Method WithSubProtocol

upgrader.go:67–76  ·  view source on GitHub ↗

WithSubProtocol 根据请求头和预期的子协议列表设置子协议 Sets the subprotocol based on the request header and the expected subprotocols list

(requestHeader http.Header, expectedSubProtocols []string)

Source from the content-addressed store, hash-verified

65// WithSubProtocol 根据请求头和预期的子协议列表设置子协议
66// Sets the subprotocol based on the request header and the expected subprotocols list
67func (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

Callers 1

doUpgradeFromConnMethod · 0.80

Calls 4

WithHeaderMethod · 0.95
GetIntersectionElemFunction · 0.92
SplitFunction · 0.92
GetMethod · 0.45

Tested by

no test coverage detected