@@ -45,6 +45,11 @@ type AcceptOptions struct {
45
45
// If you do, remember that if you store secure data in cookies, you wil need to verify the
46
46
// Origin header yourself otherwise you are exposing yourself to a CSRF attack.
47
47
InsecureSkipVerify bool
48
+
49
+ // Compression sets the compression options.
50
+ // By default, compression is disabled.
51
+ // See docs on the CompressionOptions type.
52
+ Compression * CompressionOptions
48
53
}
49
54
50
55
func verifyClientRequest (w http.ResponseWriter , r * http.Request ) error {
@@ -240,6 +245,49 @@ type DialOptions struct {
240
245
241
246
// Subprotocols lists the subprotocols to negotiate with the server.
242
247
Subprotocols []string
248
+
249
+ // Compression sets the compression options.
250
+ // By default, compression is disabled.
251
+ // See docs on the CompressionOptions type.
252
+ Compression CompressionOptions
253
+ }
254
+
255
+ // CompressionOptions describes the available compression options.
256
+ //
257
+ // See https://tools.ietf.org/html/rfc7692
258
+ //
259
+ // Enabling compression may spike memory usage as each flate.Writer takes up 1.2 MB.
260
+ // See https://github.com/gorilla/websocket/issues/203
261
+ // Benchmark before enabling in production.
262
+ //
263
+ // This API is experimental and subject to change.
264
+ type CompressionOptions struct {
265
+ // ContextTakeover controls whether context takeover is enabled.
266
+ //
267
+ // If ContextTakeover == false, then a flate.Writer will be grabbed
268
+ // from the pool as needed for every message written to the connection.
269
+ //
270
+ // If ContextTakeover == true, then a flate.Writer will be allocated for each connection.
271
+ // This allows more efficient compression as the sliding window from previous
272
+ // messages will be used instead of resetting in between every message.
273
+ // The downside is that for every connection there will be a fixed allocation
274
+ // for the flate.Writer.
275
+ //
276
+ // See https://www.igvita.com/2013/11/27/configuring-and-optimizing-websocket-compression.
277
+ ContextTakeover bool
278
+
279
+ // Level controls the compression level negotiated.
280
+ // Defaults to flate.BestSpeed.
281
+ Level int
282
+
283
+ // Threshold controls the minimum message size in bytes before compression is used.
284
+ // In the case of ContextTakeover == false, a flate.Writer will not be grabbed
285
+ // from the pool until the message exceeds this threshold.
286
+ //
287
+ // Must not be greater than 4096 as that is the write buffer's size.
288
+ //
289
+ // Defaults to 512.
290
+ Threshold int
243
291
}
244
292
245
293
// Dial performs a WebSocket handshake on the given url with the given options.
0 commit comments