code: private void encodeHeader(ByteBuf out, CharSequence name, CharSequence value, boolean sensitive, long headerSize) {
          // If the header value is sensitive then it must never be indexed
          if (sensitive) {
              int nameIndex = getNameIndex(name);
              encodeLiteral(out, name, value, IndexType.NEVER, nameIndex);
              return;
          }
  
          // If the peer will only use the static table
          if (maxHeaderTableSize == 0) {
              int staticTableIndex = HpackStaticTable.getIndex(name, value);
              if (staticTableIndex == -1) {
                  int nameIndex = HpackStaticTable.getIndex(name);
                  encodeLiteral(out, name, value, IndexType.NONE, nameIndex);
              } else {
                  encodeInteger(out, 0x80, 7, staticTableIndex);
              }
              return;
          }
  
          // If the headerSize is greater than the max table size then it must be encoded literally
          if (headerSize > maxHeaderTableSize) {
              int nameIndex = getNameIndex(name);
              encodeLiteral(out, name, value, IndexType.NONE, nameIndex);
              return;
          }
  
          HeaderEntry headerField = getEntry(name, value);
          if (headerField != null) {
              int index = getIndex(headerField.index) + HpackStaticTable.length;
              // Section 6.1. Indexed Header Field Representation
              encodeInteger(out, 0x80, 7, index);
          } else {
              int staticTableIndex = HpackStaticTable.getIndex(name, value);
              if (staticTableIndex != -1) {
                  // Section 6.1. Indexed Header Field Representation
                  encodeInteger(out, 0x80, 7, staticTableIndex);
              } else {
                  ensureCapacity(headerSize);
                  encodeLiteral(out, name, value, IndexType.INCREMENTAL, getNameIndex(name));
                  add(name, value, headerSize);
              }
          }
      }
docs: Encode the header field into the header block.
  
  <strong>The given {@link CharSequence}s must be immutable!</strong>