code: public void encodeHeader(OutputStream out, byte[] name, byte[] value, boolean sensitive) throws IOException {
  
      // 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 (capacity == 0) {
        int staticTableIndex = StaticTable.getIndex(name, value);
        if (staticTableIndex == -1) {
          int nameIndex = StaticTable.getIndex(name);
          encodeLiteral(out, name, value, IndexType.NONE, nameIndex);
        } else {
          encodeInteger(out, 0x80, 7, staticTableIndex);
        }
        return;
      }
  
      int headerSize = HeaderField.sizeOf(name, value);
  
      // If the headerSize is greater than the max table size then it must be encoded literally
      if (headerSize > capacity) {
        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) + StaticTable.length;
        // Section 6.1. Indexed Header Field Representation
        encodeInteger(out, 0x80, 7, index);
      } else {
        int staticTableIndex = StaticTable.getIndex(name, value);
        if (staticTableIndex != -1) {
          // Section 6.1. Indexed Header Field Representation
          encodeInteger(out, 0x80, 7, staticTableIndex);
        } else {
          int nameIndex = getNameIndex(name);
          if (useIndexing) {
            ensureCapacity(headerSize);
          }
          IndexType indexType = useIndexing ? IndexType.INCREMENTAL : IndexType.NONE;
          encodeLiteral(out, name, value, indexType, nameIndex);
          if (useIndexing) {
            add(name, value);
          }
        }
      }
    }
docs: Encode the header field into the header block.