Skip to content

Commit 696c8e2

Browse files
remove N=1 check when decoding a literal field line with name reference (#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
1 parent 9160514 commit 696c8e2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

decoder.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,13 @@ func (d *Decoder) parseIndexedHeaderField() error {
196196

197197
func (d *Decoder) parseLiteralHeaderField() error {
198198
buf := d.buf
199-
if buf[0]&0x20 > 0 || buf[0]&0x10 == 0 {
199+
if buf[0]&0x10 == 0 {
200200
return errNoDynamicTable
201201
}
202+
// We don't need to check the value of the N-bit here.
203+
// It's only relevant when re-encoding header fields,
204+
// and determines whether the header field can be added to the dynamic table.
205+
// Since we don't support the dynamic table, we can ignore it.
202206
index, buf, err := readVarInt(4, buf)
203207
if err != nil {
204208
return err

decoder_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,21 @@ func TestDecoderInvalidIndexedHeaderFields(t *testing.T) {
119119
}
120120

121121
func TestDecoderLiteralHeaderFieldWithNameReference(t *testing.T) {
122+
t.Run("without the N-bit", func(t *testing.T) {
123+
testDecoderLiteralHeaderFieldWithNameReference(t, false)
124+
})
125+
t.Run("with the N-bit", func(t *testing.T) {
126+
testDecoderLiteralHeaderFieldWithNameReference(t, true)
127+
})
128+
}
129+
130+
func testDecoderLiteralHeaderFieldWithNameReference(t *testing.T, n bool) {
122131
decoder := newRecordingDecoder()
123132
data := appendVarInt(nil, 4, 49)
124133
data[0] ^= 0x40 | 0x10
134+
if n {
135+
data[0] |= 0x20
136+
}
125137
data = appendVarInt(data, 7, 6)
126138
data = append(data, []byte("foobar")...)
127139
doPartialWrites(t, decoder, insertPrefix(data))

0 commit comments

Comments
 (0)