Skip to content

Commit

Permalink
remove N=1 check when decoding a literal field line with name referen…
Browse files Browse the repository at this point in the history
…ce (#52)

* remove N=1 check when decoding a literal field line with name reference

This field is only used to determine if the dynamic table can be used
when this field is re-encoded. Since we currently don't support use of
the dynamic table, the N value is irrelevant.

* add comment and test
  • Loading branch information
marten-seemann authored Sep 4, 2024
1 parent 9160514 commit 696c8e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 696c8e2

Please sign in to comment.