Skip to content

x/net/websocket: Add the Conn.FrameDataLength and NewClient2 #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update hybi.go
hybiClientHandshake: add return http.Response for NewClient
  • Loading branch information
ruyi789 authored Aug 28, 2023
commit 9fc6f099c36211e2d5bfbc01dd163b6e8abea45b
26 changes: 13 additions & 13 deletions websocket/hybi.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func getNonceAccept(nonce []byte) (expected []byte, err error) {
}

// Client handshake described in draft-ietf-hybi-thewebsocket-protocol-17
func hybiClientHandshake(config *Config, br *bufio.Reader, bw *bufio.Writer) (err error) {
func hybiClientHandshake(config *Config, br *bufio.Reader, bw *bufio.Writer) (resp *http.Response, err error) {
bw.WriteString("GET " + config.Location.RequestURI() + " HTTP/1.1\r\n")

// According to RFC 6874, an HTTP client, proxy, or other
Expand All @@ -419,7 +419,7 @@ func hybiClientHandshake(config *Config, br *bufio.Reader, bw *bufio.Writer) (er
bw.WriteString("Origin: " + strings.ToLower(config.Origin.String()) + "\r\n")

if config.Version != ProtocolVersionHybi13 {
return ErrBadProtocolVersion
return nil, ErrBadProtocolVersion
}

bw.WriteString("Sec-WebSocket-Version: " + fmt.Sprintf("%d", config.Version) + "\r\n")
Expand All @@ -429,34 +429,34 @@ func hybiClientHandshake(config *Config, br *bufio.Reader, bw *bufio.Writer) (er
// TODO(ukai): send Sec-WebSocket-Extensions.
err = config.Header.WriteSubset(bw, handshakeHeader)
if err != nil {
return err
return nil, err
}

bw.WriteString("\r\n")
if err = bw.Flush(); err != nil {
return err
return nil, err
}

resp, err := http.ReadResponse(br, &http.Request{Method: "GET"})
resp, err = http.ReadResponse(br, &http.Request{Method: "GET"})
if err != nil {
return err
return
}
if resp.StatusCode != 101 {
return ErrBadStatus
return resp, ErrBadStatus
}
if strings.ToLower(resp.Header.Get("Upgrade")) != "websocket" ||
strings.ToLower(resp.Header.Get("Connection")) != "upgrade" {
return ErrBadUpgrade
return resp, ErrBadUpgrade
}
expectedAccept, err := getNonceAccept(nonce)
if err != nil {
return err
return resp, err
}
if resp.Header.Get("Sec-WebSocket-Accept") != string(expectedAccept) {
return ErrChallengeResponse
return resp, ErrChallengeResponse
}
if resp.Header.Get("Sec-WebSocket-Extensions") != "" {
return ErrUnsupportedExtensions
return resp, ErrUnsupportedExtensions
}
offeredProtocol := resp.Header.Get("Sec-WebSocket-Protocol")
if offeredProtocol != "" {
Expand All @@ -468,12 +468,12 @@ func hybiClientHandshake(config *Config, br *bufio.Reader, bw *bufio.Writer) (er
}
}
if !protocolMatched {
return ErrBadWebSocketProtocol
return resp, ErrBadWebSocketProtocol
}
config.Protocol = []string{offeredProtocol}
}

return nil
return resp, nil
}

// newHybiClientConn creates a client WebSocket connection after handshake.
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy