Skip to content

Commit

Permalink
Add Handshake.Header field
Browse files Browse the repository at this point in the history
  • Loading branch information
PotatoCloud committed Jun 18, 2024
1 parent 4f03007 commit d6f59f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type Handshake struct {

// Extensions is the list of negotiated extensions.
Extensions []httphead.Option

// Header all request headers obtained during handshake
Header http.Header
}

// Errors used by the websocket client.
Expand Down
11 changes: 11 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ func (u HTTPUpgrader) Upgrade(r *http.Request, w http.ResponseWriter) (conn net.
if h := u.Header; h != nil {
header[0] = HandshakeHeaderHTTP(h)
}

// set handshake header
hs.Header = r.Header

if err == nil {
httpWriteResponseUpgrade(rw.Writer, strToBytes(nonce), hs, header.WriteTo)
err = rw.Writer.Flush()
Expand Down Expand Up @@ -498,6 +502,10 @@ func (u Upgrader) Upgrade(conn io.ReadWriter) (hs Handshake, err error) {

nonce = make([]byte, nonceSize)
)

// init handshake headers
hs.Header = make(http.Header)

for err == nil {
line, e := readLine(br)
if e != nil {
Expand All @@ -514,6 +522,9 @@ func (u Upgrader) Upgrade(conn io.ReadWriter) (hs Handshake, err error) {
break
}

// copy and add header
hs.Header.Add(btsToString(bytes.Clone(k)), btsToString(bytes.Clone(v)))

switch btsToString(k) {
case headerHostCanonical:
headerSeen |= headerSeenHost
Expand Down

0 comments on commit d6f59f9

Please sign in to comment.