@@ -45,6 +45,12 @@ type AcceptOptions struct {
4545 // If you do, remember that if you store secure data in cookies, you wil need to verify the
4646 // Origin header yourself otherwise you are exposing yourself to a CSRF attack.
4747 InsecureSkipVerify bool
48+
49+ // Compression sets the WebSocket compression extension options.
50+ // If unset, CompressionNoContextTakeover is negotiated with
51+ // a threshold of 1024 bytes, flate.BestSpeed and only text messages
52+ // are compressed.
53+ Compression * CompressionOptions
4854}
4955
5056func verifyClientRequest (w http.ResponseWriter , r * http.Request ) error {
@@ -240,8 +246,42 @@ type DialOptions struct {
240246
241247 // Subprotocols lists the subprotocols to negotiate with the server.
242248 Subprotocols []string
249+
250+ // Compression sets the WebSocket compression extension options.
251+ // If unset, CompressionNoContextTakeover is negotiated with
252+ // a threshold of 1024 bytes, flate.BestSpeed and only text messages
253+ // are compressed.
254+ Compression * CompressionOptions
243255}
244256
257+ type CompressionOptions struct {
258+ // Type sets the WebSocket compression extension type.
259+ // Defaults to CompressionNoContextTakeover.
260+ Type CompressionType
261+
262+ // Level controls the compression level negotiated.
263+ // Defaults to flate.BestSpeed.
264+ Level int
265+
266+ // Threshold controls the minimum size in bytes of the message
267+ // before compression is enabled.
268+ // Defaults to 1024.
269+ Threshold int
270+
271+ // Binary controls whether to compression binary messages.
272+ Binary bool
273+
274+ // Text controls whether to compress text messages.
275+ Text bool
276+ }
277+
278+ type CompressionType int
279+
280+ const (
281+ CompressionNoContextTakeover CompressionType = iota
282+ CompressionContextTakeover
283+ )
284+
245285// Dial performs a WebSocket handshake on the given url with the given options.
246286// The response is the WebSocket handshake response from the server.
247287// If an error occurs, the returned response may be non nil. However, you can only
0 commit comments