@@ -95,6 +95,12 @@ var ErrUnexpectedCompressionBit = ws.ProtocolError(
9595// UnsetBit clears the Per-Message Compression bit in header h and returns its
9696// modified copy. It reports whether compression bit was set in header h.
9797// It returns non-nil error if compression bit has unexpected value.
98+ //
99+ // This function's main purpose is to be compatible with "Framing" section of
100+ // the Compression Extensions for WebSocket RFC. If you don't need to work with
101+ // chains of extenstions then IsCompressed() could be enought to check if
102+ // message is compressed.
103+ // See https://tools.ietf.org/html/rfc7692#section-6.2
98104func UnsetBit (h ws.Header ) (_ ws.Header , wasSet bool , err error ) {
99105 var s MessageState
100106 h , err = s .UnsetBits (h )
@@ -110,6 +116,19 @@ func SetBit(h ws.Header) (_ ws.Header, err error) {
110116 return s .SetBits (h )
111117}
112118
119+ // IsCompressed reports whether the Per-Message Compression bit is set in
120+ // header h.
121+ // It returns non-nil error if compression bit has unexpected value.
122+ //
123+ // If you need to be fully compatible with Compression Extensions for WebSocket
124+ // RFC and work with chains of extensions, take a look at the UnsetBit()
125+ // instead. That is, IsCompressed() is a shortcut for UnsetBit() with reduced
126+ // number of return values.
127+ func IsCompressed (h ws.Header ) (bool , error ) {
128+ _ , isSet , err := UnsetBit (h )
129+ return isSet , err
130+ }
131+
113132// MessageState holds message compression state.
114133//
115134// It is consulted during SetBits(h) call to make a decision whether we must
0 commit comments