Ejemplo 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(string name, string value)
        {
            int index = GetIndex(name);

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

            // Note this assumes all entries for a given header field are sequential.
            while (index <= Length)
            {
                var entry = Get(index);
                if (!name.Equals(entry.Name, StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }

                if (HpackUtil.Equals(value, entry.Value))
                {
                    return(index);
                }

                index++;
            }

            return(-1);
        }
Ejemplo n.º 2
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(string name)
        {
            if (Length() == 0 || name == null)
            {
                return(-1);
            }

            int h     = Hash(name);
            int i     = Index(h);
            int index = -1;

            for (var e = headerFields[i]; e != null; e = e.Next)
            {
                if (e.Hash == h && HpackUtil.Equals(name, e.Name))
                {
                    index = e.Index;
                    break;
                }
            }

            return(GetIndex(index));
        }