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));
        }