code: func CheckHeader(h Header, s State) error {
  	if h.OpCode.IsReserved() {
  		return ErrProtocolOpCodeReserved
  	}
  	if h.OpCode.IsControl() {
  		if h.Length > MaxControlFramePayloadSize {
  			return ErrProtocolControlPayloadOverflow
  		}
  		if !h.Fin {
  			return ErrProtocolControlNotFinal
  		}
  	}
  
  	switch {
  	// [RFC6455]: MUST be 0 unless an extension is negotiated that defines meanings for
  	// non-zero values. If a nonzero value is received and none of the
  	// negotiated extensions defines the meaning of such a nonzero value, the
  	// receiving endpoint MUST _Fail the WebSocket Connection_.
  	case h.Rsv != 0 && !s.Extended():
  		return ErrProtocolNonZeroRsv
  
  	// [RFC6455]: The server MUST close the connection upon receiving a frame that is not masked.
  	// In this case, a server MAY send a Close frame with a status code of 1002 (protocol error)
  	// as defined in Section 7.4.1. A server MUST NOT mask any frames that it sends to the client.
  	// A client MUST close a connection if it detects a masked frame. In this case, it MAY use the
  	// status code 1002 (protocol error) as defined in Section 7.4.1.
  	case s.ServerSide() && !h.Masked:
  		return ErrProtocolMaskRequired
  	case s.ClientSide() && h.Masked:
  		return ErrProtocolMaskUnexpected
  
  	// [RFC6455]: See detailed explanation in 5.4 section.
  	case s.Fragmented() && !h.OpCode.IsControl() && h.OpCode != OpContinuation:
  		return ErrProtocolContinuationExpected
  	case !s.Fragmented() && h.OpCode == OpContinuation:
  		return ErrProtocolContinuationUnexpected
  	}
  
  	return nil
  }
docs: // CheckHeader checks h to contain valid header data for given state s.
  //
  // Note that zero state (0) means that state is clean,
  // neither server or client side, nor fragmented, nor extended.