private void InsertHeader(IHeaderListener headerListener, byte[] name, byte[] value, HpackUtil.IndexType indexType) { this.AddHeader(headerListener, name, value, indexType == HpackUtil.IndexType.NEVER); switch(indexType) { case HpackUtil.IndexType.NONE: case HpackUtil.IndexType.NEVER: break; case HpackUtil.IndexType.INCREMENTAL: this.dynamicTable.Add(new HeaderField(name, value)); break; default: throw new Exception("should not reach here"); } }
/// <summary> /// Encode literal header field according to Section 6.2. /// </summary> /// <param name="output">Output.</param> /// <param name="name">Name.</param> /// <param name="value">Value.</param> /// <param name="indexType">Index type.</param> /// <param name="nameIndex">Name index.</param> private void EncodeLiteral(BinaryWriter output, byte[] name, byte[] value, HpackUtil.IndexType indexType, int nameIndex) { var mask = 0; var prefixBits = 0; switch(indexType) { case HpackUtil.IndexType.INCREMENTAL: mask = 0x40; prefixBits = 6; break; case HpackUtil.IndexType.NONE: mask = 0x00; prefixBits = 4; break; case HpackUtil.IndexType.NEVER: mask = 0x10; prefixBits = 4; break; default: throw new Exception("should not reach here"); } Encoder.EncodeInteger(output, mask, prefixBits, nameIndex == -1 ? 0 : nameIndex); if (nameIndex == -1) { this.EncodeStringLiteral(output, name); } this.EncodeStringLiteral(output, value); }