enable compression by default

This commit is contained in:
Marc Tarnutzer
2023-05-05 22:00:25 +02:00
parent ee9502bc3e
commit c86e907142
3 changed files with 17 additions and 54 deletions

View File

@@ -29,23 +29,28 @@ type Connection struct {
mutex sync.Mutex
}
func NewConnection(ctx context.Context, url string, requestHeader http.Header, enableCompression bool) (*Connection, error) {
func NewConnection(ctx context.Context, url string, requestHeader http.Header) (*Connection, error) {
dialer := ws.Dialer{
Header: ws.HandshakeHeaderHTTP(requestHeader),
}
state := ws.StateClientSide
if enableCompression {
state |= ws.StateExtended
dialer.Extensions = []httphead.Option{
Extensions: []httphead.Option{
wsflate.DefaultParameters.Option(),
}
},
}
conn, _, _, err := dialer.Dial(ctx, url)
conn, _, hs, err := dialer.Dial(ctx, url)
if err != nil {
return nil, fmt.Errorf("failed to dial: %w", err)
}
enableCompression := false
state := ws.StateClientSide
for _, extension := range hs.Extensions {
if string(extension.Name) == wsflate.ExtensionName {
enableCompression = true
state |= ws.StateExtended
break
}
}
// reader
var flateReader *wsflate.Reader
var msgState wsflate.MessageState