github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/nhooyr.io/websocket/compress.go (about)

     1  package websocket
     2  
     3  // CompressionMode represents the modes available to the deflate extension.
     4  // See https://tools.ietf.org/html/rfc7692
     5  //
     6  // A compatibility layer is implemented for the older deflate-frame extension used
     7  // by safari. See https://tools.ietf.org/html/draft-tyoshino-hybi-websocket-perframe-deflate-06
     8  // It will work the same in every way except that we cannot signal to the peer we
     9  // want to use no context takeover on our side, we can only signal that they should.
    10  // It is however currently disabled due to Safari bugs. See https://github.com/nhooyr/websocket/issues/218
    11  type CompressionMode int
    12  
    13  const (
    14  	// CompressionNoContextTakeover grabs a new flate.Reader and flate.Writer as needed
    15  	// for every message. This applies to both server and client side.
    16  	//
    17  	// This means less efficient compression as the sliding window from previous messages
    18  	// will not be used but the memory overhead will be lower if the connections
    19  	// are long lived and seldom used.
    20  	//
    21  	// The message will only be compressed if greater than 512 bytes.
    22  	CompressionNoContextTakeover CompressionMode = iota
    23  
    24  	// CompressionContextTakeover uses a flate.Reader and flate.Writer per connection.
    25  	// This enables reusing the sliding window from previous messages.
    26  	// As most WebSocket protocols are repetitive, this can be very efficient.
    27  	// It carries an overhead of 8 kB for every connection compared to CompressionNoContextTakeover.
    28  	//
    29  	// If the peer negotiates NoContextTakeover on the client or server side, it will be
    30  	// used instead as this is required by the RFC.
    31  	CompressionContextTakeover
    32  
    33  	// CompressionDisabled disables the deflate extension.
    34  	//
    35  	// Use this if you are using a predominantly binary protocol with very
    36  	// little duplication in between messages or CPU and memory are more
    37  	// important than bandwidth.
    38  	CompressionDisabled
    39  )