diff --git a/decoder.go b/decoder.go index c900194..88ea8eb 100644 --- a/decoder.go +++ b/decoder.go @@ -196,9 +196,13 @@ func (d *Decoder) parseIndexedHeaderField() error { func (d *Decoder) parseLiteralHeaderField() error { buf := d.buf - if buf[0]&0x20 > 0 || buf[0]&0x10 == 0 { + if buf[0]&0x10 == 0 { return errNoDynamicTable } + // We don't need to check the value of the N-bit here. + // It's only relevant when re-encoding header fields, + // and determines whether the header field can be added to the dynamic table. + // Since we don't support the dynamic table, we can ignore it. index, buf, err := readVarInt(4, buf) if err != nil { return err diff --git a/decoder_test.go b/decoder_test.go index ec75962..0a06cda 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -119,9 +119,21 @@ func TestDecoderInvalidIndexedHeaderFields(t *testing.T) { } func TestDecoderLiteralHeaderFieldWithNameReference(t *testing.T) { + t.Run("without the N-bit", func(t *testing.T) { + testDecoderLiteralHeaderFieldWithNameReference(t, false) + }) + t.Run("with the N-bit", func(t *testing.T) { + testDecoderLiteralHeaderFieldWithNameReference(t, true) + }) +} + +func testDecoderLiteralHeaderFieldWithNameReference(t *testing.T, n bool) { decoder := newRecordingDecoder() data := appendVarInt(nil, 4, 49) data[0] ^= 0x40 | 0x10 + if n { + data[0] |= 0x20 + } data = appendVarInt(data, 7, 6) data = append(data, []byte("foobar")...) doPartialWrites(t, decoder, insertPrefix(data))