@@ -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,45 @@ 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+ // CompressionOptions describes the available compression options.
258+ type CompressionOptions struct {
259+ // Type sets the WebSocket compression extension type.
260+ // Defaults to CompressionNoContextTakeover.
261+ Type CompressionType
262+
263+ // Level controls the compression level negotiated.
264+ // Defaults to flate.BestSpeed.
265+ Level int
266+
267+ // Threshold controls the minimum size in bytes of the message
268+ // before compression is enabled.
269+ // Defaults to 1024.
270+ Threshold int
271+
272+ // Binary controls whether to compression binary messages.
273+ Binary bool
274+
275+ // Text controls whether to compress text messages.
276+ Text bool
277+ }
278+
279+ // CompressionType describes the type of compression enabled.
280+ type CompressionType int
281+
282+ // The CompressionType constants.
283+ const (
284+ CompressionNoContextTakeover CompressionType = iota
285+ CompressionContextTakeover
286+ )
287+
245288// Dial performs a WebSocket handshake on the given url with the given options.
246289// The response is the WebSocket handshake response from the server.
247290// If an error occurs, the returned response may be non nil. However, you can only
0 commit comments