{"record":{"id":"abafd2cbf1d2f2ab","repo":"gorilla/websocket","slug":"websocket-invalid-compression-negotiation","errorCode":null,"errorMessage":"websocket: invalid compression negotiation","messagePattern":"websocket: invalid compression negotiation","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client.go","lineNumber":26,"sourceCode":"\t\"bytes\"\n\t\"context\"\n\t\"crypto/tls\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"net\"\n\t\"net/http\"\n\t\"net/http/httptrace\"\n\t\"net/url\"\n\t\"strings\"\n\t\"time\"\n)\n\n// ErrBadHandshake is returned when the server response to opening handshake is\n// invalid.\nvar ErrBadHandshake = errors.New(\"websocket: bad handshake\")\n\nvar errInvalidCompression = errors.New(\"websocket: invalid compression negotiation\")\n\n// NewClient creates a new client connection using the given net connection.\n// The URL u specifies the host and request URI. Use requestHeader to specify\n// the origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies\n// (Cookie). Use the response.Header to get the selected subprotocol\n// (Sec-WebSocket-Protocol) and cookies (Set-Cookie).\n//\n// If the WebSocket handshake fails, ErrBadHandshake is returned along with a\n// non-nil *http.Response so that callers can handle redirects, authentication,\n// etc.\n//\n// Deprecated: Use Dialer instead.\nfunc NewClient(netConn net.Conn, u *url.URL, requestHeader http.Header, readBufSize, writeBufSize int) (c *Conn, response *http.Response, err error) {\n\td := Dialer{\n\t\tReadBufferSize:  readBufSize,\n\t\tWriteBufferSize: writeBufSize,\n\t\tNetDial: func(net, addr string) (net.Conn, error) {\n\t\t\treturn netConn, nil","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/gorilla/websocket/blob/e064f32e3674d9d79a8fd417b5bc06fa5c6cad8f/client.go#L8-L44","documentation":"errInvalidCompression is an internal error returned by DialContext when the permessage-deflate extension negotiation produces an invalid result. It means the client and server agreed on compression in a way the library cannot honor. It is unexported; callers cannot match it directly.","triggerScenarios":"Calling DialContext with EnableCompression set to true when the negotiated compression extension parameters from the server response are invalid (e.g. server echoes extension parameters outside what the client offered, like an unexpected context takeover or no-context-takeover value).","commonSituations":"Dialing a non-conformant server that echoes back malformed Sec-WebSocket-Extensions parameters during compression negotiation; rare in practice, mostly seen with custom or buggy server implementations.","solutions":["Disable compression by not setting dialer.EnableCompression = true and retry","Upgrade to the latest gorilla/websocket version in case the negotiation bug is fixed","Fix or report the server's Sec-WebSocket-Extensions response to conform to RFC 7692"],"exampleFix":"// before\ndialer := websocket.Dialer{EnableCompression: true}\n// after (workaround for non-conformant server)\ndialer := websocket.Dialer{} // compression disabled","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"conn, _, err := dialer.DialContext(ctx, url, nil)\nif err != nil {\n    // errInvalidCompression is unexported; fall back to a non-compressed dial\n    dialer.EnableCompression = false\n    return dialer.DialContext(ctx, url, nil)\n}","preventionTips":["Only enable compression with servers known to implement RFC 7692 correctly","Keep gorilla/websocket updated so negotiation fixes are picked up","Prefer default (no compression) unless payload sizes justify it"],"tags":["websocket","compression","handshake"],"backgroundTag":"compression-negotiation-failed","analyzedSha":"e064f32e3674d9d79a8fd417b5bc06fa5c6cad8f","analyzedAt":"2026-08-31T12:40:58.222Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}