Exemplo n.º 1
0
        /// <summary>
        /// Returns the index value for the given header field in the static table.
        /// Returns -1 if the header field is not in the static table.
        /// </summary>
        /// <returns>The index.</returns>
        /// <param name="name">Name.</param>
        /// <param name="value">Value.</param>
        public static int GetIndex(byte[] name, byte[] value)
        {
            int index = GetIndex(name);

            if (index == -1)
            {
                return(-1);
            }

            // Note this assumes all entries for a given header field are sequential.
            while (index <= StaticTable.Length)
            {
                HeaderField entry = GetEntry(index);
                if (!HPackUtil.Equals(name, entry.Name))
                {
                    break;
                }
                if (HPackUtil.Equals(value, entry.Value))
                {
                    return(index);
                }
                index++;
            }

            return(-1);
        }
Exemplo n.º 2
0
        public override bool Equals(Object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            if (!(obj is HeaderField))
            {
                return(false);
            }
            HeaderField other       = (HeaderField)obj;
            bool        nameEquals  = HPackUtil.Equals(name, other.name);
            bool        valueEquals = HPackUtil.Equals(value, other.value);

            return(nameEquals && valueEquals);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the header entry with the lowest index value for the header field.
        /// Returns null if header field is not in the dynamic table.
        /// </summary>
        /// <returns>The entry.</returns>
        /// <param name="name">Name.</param>
        /// <param name="value">Value.</param>
        private HeaderEntry GetEntry(byte[] name, byte[] value)
        {
            if (this.Length() == 0 || name == null || value == null)
            {
                return(null);
            }
            int h = Encoder.Hash(name);
            int i = Encoder.Index(h);

            for (HeaderEntry e = headerFields[i]; e != null; e = e.Next)
            {
                if (e.Hash == h && HPackUtil.Equals(name, e.Name) && HPackUtil.Equals(value, e.Value))
                {
                    return(e);
                }
            }
            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the lowest index value for the header field name in the dynamic table.
        /// Returns -1 if the header field name is not in the dynamic table.
        /// </summary>
        /// <returns>The index.</returns>
        /// <param name="name">Name.</param>
        private int GetIndex(byte[] name)
        {
            if (this.Length() == 0 || name == null)
            {
                return(-1);
            }
            int h     = Encoder.Hash(name);
            int i     = Encoder.Index(h);
            int index = -1;

            for (HeaderEntry e = headerFields[i]; e != null; e = e.Next)
            {
                if (e.Hash == h && HPackUtil.Equals(name, e.Name))
                {
                    index = e.Index;
                    break;
                }
            }
            return(this.GetIndex(index));
        }
Exemplo n.º 5
0
        private void InsertHeader(AddHeaderDelegate addHeaderDelegate, byte[] name, byte[] value, HPackUtil.IndexType indexType)
        {
            this.AddHeader(addHeaderDelegate, 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");
            }
        }
Exemplo n.º 6
0
 public HeaderField(byte[] name, byte[] value)
 {
     this.name  = (byte[])HPackUtil.RequireNonNull(name);
     this.value = (byte[])HPackUtil.RequireNonNull(value);
 }
Exemplo n.º 7
0
        /// <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)
        {
            int mask;
            int prefixBits;
            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);
        }