diff options
Diffstat (limited to 'vendor/golang.org/x/net/http2/hpack/hpack.go')
-rw-r--r-- | vendor/golang.org/x/net/http2/hpack/hpack.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/vendor/golang.org/x/net/http2/hpack/hpack.go b/vendor/golang.org/x/net/http2/hpack/hpack.go index 176644a..85f18a2 100644 --- a/vendor/golang.org/x/net/http2/hpack/hpack.go +++ b/vendor/golang.org/x/net/http2/hpack/hpack.go | |||
@@ -92,6 +92,8 @@ type Decoder struct { | |||
92 | // saveBuf is previous data passed to Write which we weren't able | 92 | // saveBuf is previous data passed to Write which we weren't able |
93 | // to fully parse before. Unlike buf, we own this data. | 93 | // to fully parse before. Unlike buf, we own this data. |
94 | saveBuf bytes.Buffer | 94 | saveBuf bytes.Buffer |
95 | |||
96 | firstField bool // processing the first field of the header block | ||
95 | } | 97 | } |
96 | 98 | ||
97 | // NewDecoder returns a new decoder with the provided maximum dynamic | 99 | // NewDecoder returns a new decoder with the provided maximum dynamic |
@@ -101,6 +103,7 @@ func NewDecoder(maxDynamicTableSize uint32, emitFunc func(f HeaderField)) *Decod | |||
101 | d := &Decoder{ | 103 | d := &Decoder{ |
102 | emit: emitFunc, | 104 | emit: emitFunc, |
103 | emitEnabled: true, | 105 | emitEnabled: true, |
106 | firstField: true, | ||
104 | } | 107 | } |
105 | d.dynTab.table.init() | 108 | d.dynTab.table.init() |
106 | d.dynTab.allowedMaxSize = maxDynamicTableSize | 109 | d.dynTab.allowedMaxSize = maxDynamicTableSize |
@@ -226,11 +229,15 @@ func (d *Decoder) DecodeFull(p []byte) ([]HeaderField, error) { | |||
226 | return hf, nil | 229 | return hf, nil |
227 | } | 230 | } |
228 | 231 | ||
232 | // Close declares that the decoding is complete and resets the Decoder | ||
233 | // to be reused again for a new header block. If there is any remaining | ||
234 | // data in the decoder's buffer, Close returns an error. | ||
229 | func (d *Decoder) Close() error { | 235 | func (d *Decoder) Close() error { |
230 | if d.saveBuf.Len() > 0 { | 236 | if d.saveBuf.Len() > 0 { |
231 | d.saveBuf.Reset() | 237 | d.saveBuf.Reset() |
232 | return DecodingError{errors.New("truncated headers")} | 238 | return DecodingError{errors.New("truncated headers")} |
233 | } | 239 | } |
240 | d.firstField = true | ||
234 | return nil | 241 | return nil |
235 | } | 242 | } |
236 | 243 | ||
@@ -266,6 +273,7 @@ func (d *Decoder) Write(p []byte) (n int, err error) { | |||
266 | d.saveBuf.Write(d.buf) | 273 | d.saveBuf.Write(d.buf) |
267 | return len(p), nil | 274 | return len(p), nil |
268 | } | 275 | } |
276 | d.firstField = false | ||
269 | if err != nil { | 277 | if err != nil { |
270 | break | 278 | break |
271 | } | 279 | } |
@@ -389,6 +397,12 @@ func (d *Decoder) callEmit(hf HeaderField) error { | |||
389 | 397 | ||
390 | // (same invariants and behavior as parseHeaderFieldRepr) | 398 | // (same invariants and behavior as parseHeaderFieldRepr) |
391 | func (d *Decoder) parseDynamicTableSizeUpdate() error { | 399 | func (d *Decoder) parseDynamicTableSizeUpdate() error { |
400 | // RFC 7541, sec 4.2: This dynamic table size update MUST occur at the | ||
401 | // beginning of the first header block following the change to the dynamic table size. | ||
402 | if !d.firstField && d.dynTab.size > 0 { | ||
403 | return DecodingError{errors.New("dynamic table size update MUST occur at the beginning of a header block")} | ||
404 | } | ||
405 | |||
392 | buf := d.buf | 406 | buf := d.buf |
393 | size, buf, err := readVarInt(5, buf) | 407 | size, buf, err := readVarInt(5, buf) |
394 | if err != nil { | 408 | if err != nil { |