private void OnIndexedHeaderName(int index)
        {
            HeaderField header = GetHeader(index);

            _headerName       = header.Name;
            _headerNameLength = header.Name.Length;
            _state            = State.HeaderValueLength;
        }
Beispiel #2
0
        public bool EncodeHeader(Span <byte> buffer, int staticTableIndex, HeaderEncodingHint encodingHint, string name, string value,
                                 Encoding?valueEncoding, out int bytesWritten)
        {
            Debug.Assert(!_pendingTableSizeUpdate, "Dynamic table size update should be encoded before headers.");

            // Never index sensitive value.
            if (encodingHint == HeaderEncodingHint.NeverIndex)
            {
                int index = ResolveDynamicTableIndex(staticTableIndex, name);

                return(index == -1
                    ? HPackEncoder.EncodeLiteralHeaderFieldNeverIndexingNewName(name, value, valueEncoding, buffer, out bytesWritten)
                    : HPackEncoder.EncodeLiteralHeaderFieldNeverIndexing(index, value, valueEncoding, buffer, out bytesWritten));
            }

            // No dynamic table. Only use the static table.
            if (!_allowDynamicCompression || _maxHeaderTableSize == 0 || encodingHint == HeaderEncodingHint.IgnoreIndex)
            {
                return(staticTableIndex == -1
                    ? HPackEncoder.EncodeLiteralHeaderFieldWithoutIndexingNewName(name, value, valueEncoding, buffer, out bytesWritten)
                    : HPackEncoder.EncodeLiteralHeaderFieldWithoutIndexing(staticTableIndex, value, valueEncoding, buffer, out bytesWritten));
            }

            // Header is greater than the maximum table size.
            // Don't attempt to add dynamic header as all existing dynamic headers will be removed.
            var headerLength = HeaderField.GetLength(name.Length, valueEncoding?.GetByteCount(value) ?? value.Length);

            if (headerLength > _maxHeaderTableSize)
            {
                int index = ResolveDynamicTableIndex(staticTableIndex, name);

                return(index == -1
                    ? HPackEncoder.EncodeLiteralHeaderFieldWithoutIndexingNewName(name, value, valueEncoding, buffer, out bytesWritten)
                    : HPackEncoder.EncodeLiteralHeaderFieldWithoutIndexing(index, value, valueEncoding, buffer, out bytesWritten));
            }

            return(EncodeDynamicHeader(buffer, staticTableIndex, name, value, headerLength, valueEncoding, out bytesWritten));
        }
Beispiel #3
0
 public uint CalculateSize()
 {
     return((uint)HeaderField.GetLength(Name.Length, Value.Length));
 }