示例#1
0
        /// <summary>
        /// Returns the index of the best matching element in the header table.
        /// If no index was found the return value is -1.
        /// If an index was found and the name as well as the value match
        /// isFullMatch will be set to true.
        /// </summary>
        public int GetBestMatchingIndex(HeaderField field, out bool isFullMatch)
        {
            var bestMatch = -1;

            isFullMatch = false;

            var i = 1;

            foreach (var entry in StaticTable.Entries)
            {
                if (entry.Name == field.Name)
                {
                    if (bestMatch == -1)
                    {
                        // We used the lowest matching field index, which makes
                        // search for the receiver the most efficient and provides
                        // the highest chance to use the Static Table.
                        bestMatch = i;
                    }

                    if (entry.Value == field.Value)
                    {
                        // It's a perfect match!
                        isFullMatch = true;
                        return(i);
                    }
                }
                i++;
            }

            // If we don't have a full match search on in the dynamic table
            bool dynamicHasFullMatch;
            var  di = this.dynamic.GetBestMatchingIndex(field, out dynamicHasFullMatch);

            if (dynamicHasFullMatch)
            {
                isFullMatch = true;
                return(di + 1 + StaticTable.Length);
            }
            // If the dynamic table has a match at all use it's index and normalize it
            if (di != -1 && bestMatch == -1)
            {
                bestMatch = di + 1 + StaticTable.Length;
            }

            return(bestMatch);
        }
示例#2
0
        /// <summary>
        /// Handles the decoding of a fully indexed headerfield
        /// </summary>
        private void HandleDecodeIndexed()
        {
            // The index is stored as result of the first task
            var idx = this._tasks[0].IntData;

            this.Reset();
            var tableHeader = this._headerTable.GetAt(idx);

            // No need to check for validity here
            // The getAt function will already throw if the index is not valid

            AllowTableSizeUpdates = false;
            Done        = true;
            HeaderField = new HeaderField
            {
                Name      = tableHeader.Name,
                Value     = tableHeader.Value,
                Sensitive = false
            };
            HeaderSize = 32 + tableHeader.NameLen + tableHeader.ValueLen;
        }