Skip to content
Merged
Changes from all commits
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
13 changes: 9 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import (
"bufio"
"bytes"

Check failure on line 5 in client.go

View workflow job for this annotation

GitHub Actions / build

imported and not used: "bytes"
"context"
"crypto/tls"
"encoding/base64"
"encoding/binary"
"fmt"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -96,6 +98,9 @@
return nil, nil, err
}
for k, v := range c.option.RequestHeader {
if k == "Host" {
r.Host = v[0]
}
r.Header[k] = v
}
r.Header.Set(internal.Connection.Key, internal.Connection.Val)
Expand Down Expand Up @@ -219,16 +224,16 @@
// Checks the response headers to verify if the handshake was successful
func (c *connector) checkHeaders(resp *http.Response) error {
if resp.StatusCode != http.StatusSwitchingProtocols {
return ErrHandshake
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
if !internal.HttpHeaderContains(resp.Header.Get(internal.Connection.Key), internal.Connection.Val) {
return ErrHandshake
return fmt.Errorf("missing %s header", internal.Connection.Key)
}
if !strings.EqualFold(resp.Header.Get(internal.Upgrade.Key), internal.Upgrade.Val) {
return ErrHandshake
return fmt.Errorf("missing %s header", internal.Upgrade.Key)
}
if resp.Header.Get(internal.SecWebSocketAccept.Key) != internal.ComputeAcceptKey(c.secWebsocketKey) {
return ErrHandshake
return fmt.Errorf("invalid %s header", internal.SecWebSocketAccept.Key)
}
return nil
}
Loading