1
// Copyright 2014 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
17
"golang.org/x/net/http/httpguts"
18
"golang.org/x/net/http2/hpack"
21
const frameHeaderLen = 9
23
var padZeros = make([]byte, 255) // zeros for padding
25
// A FrameType is a registered frame type as defined in
26
// https://httpwg.org/specs/rfc7540.html#rfc.section.11.2
30
FrameData FrameType = 0x0
31
FrameHeaders FrameType = 0x1
32
FramePriority FrameType = 0x2
33
FrameRSTStream FrameType = 0x3
34
FrameSettings FrameType = 0x4
35
FramePushPromise FrameType = 0x5
36
FramePing FrameType = 0x6
37
FrameGoAway FrameType = 0x7
38
FrameWindowUpdate FrameType = 0x8
39
FrameContinuation FrameType = 0x9
42
var frameName = map[FrameType]string{
44
FrameHeaders: "HEADERS",
45
FramePriority: "PRIORITY",
46
FrameRSTStream: "RST_STREAM",
47
FrameSettings: "SETTINGS",
48
FramePushPromise: "PUSH_PROMISE",
50
FrameGoAway: "GOAWAY",
51
FrameWindowUpdate: "WINDOW_UPDATE",
52
FrameContinuation: "CONTINUATION",
55
func (t FrameType) String() string {
56
if s, ok := frameName[t]; ok {
59
return fmt.Sprintf("UNKNOWN_FRAME_TYPE_%d", uint8(t))
62
// Flags is a bitmask of HTTP/2 flags.
63
// The meaning of flags varies depending on the frame type.
66
// Has reports whether f contains all (0 or more) flags in v.
67
func (f Flags) Has(v Flags) bool {
71
// Frame-specific FrameHeader flag bits.
74
FlagDataEndStream Flags = 0x1
75
FlagDataPadded Flags = 0x8
78
FlagHeadersEndStream Flags = 0x1
79
FlagHeadersEndHeaders Flags = 0x4
80
FlagHeadersPadded Flags = 0x8
81
FlagHeadersPriority Flags = 0x20
84
FlagSettingsAck Flags = 0x1
87
FlagPingAck Flags = 0x1
90
FlagContinuationEndHeaders Flags = 0x4
92
FlagPushPromiseEndHeaders Flags = 0x4
93
FlagPushPromisePadded Flags = 0x8
96
var flagName = map[FrameType]map[Flags]string{
98
FlagDataEndStream: "END_STREAM",
99
FlagDataPadded: "PADDED",
102
FlagHeadersEndStream: "END_STREAM",
103
FlagHeadersEndHeaders: "END_HEADERS",
104
FlagHeadersPadded: "PADDED",
105
FlagHeadersPriority: "PRIORITY",
108
FlagSettingsAck: "ACK",
114
FlagContinuationEndHeaders: "END_HEADERS",
117
FlagPushPromiseEndHeaders: "END_HEADERS",
118
FlagPushPromisePadded: "PADDED",
122
// a frameParser parses a frame given its FrameHeader and payload
123
// bytes. The length of payload will always equal fh.Length (which
125
type frameParser func(fc *frameCache, fh FrameHeader, countError func(string), payload []byte) (Frame, error)
127
var frameParsers = map[FrameType]frameParser{
128
FrameData: parseDataFrame,
129
FrameHeaders: parseHeadersFrame,
130
FramePriority: parsePriorityFrame,
131
FrameRSTStream: parseRSTStreamFrame,
132
FrameSettings: parseSettingsFrame,
133
FramePushPromise: parsePushPromise,
134
FramePing: parsePingFrame,
135
FrameGoAway: parseGoAwayFrame,
136
FrameWindowUpdate: parseWindowUpdateFrame,
137
FrameContinuation: parseContinuationFrame,
140
func typeFrameParser(t FrameType) frameParser {
141
if f := frameParsers[t]; f != nil {
144
return parseUnknownFrame
147
// A FrameHeader is the 9 byte header of all HTTP/2 frames.
149
// See https://httpwg.org/specs/rfc7540.html#FrameHeader
150
type FrameHeader struct {
151
valid bool // caller can access []byte fields in the Frame
153
// Type is the 1 byte frame type. There are ten standard frame
154
// types, but extension frame types may be written by WriteRawFrame
155
// and will be returned by ReadFrame (as UnknownFrame).
158
// Flags are the 1 byte of 8 potential bit flags per frame.
159
// They are specific to the frame type.
162
// Length is the length of the frame, not including the 9 byte header.
163
// The maximum size is one byte less than 16MB (uint24), but only
164
// frames up to 16KB are allowed without peer agreement.
167
// StreamID is which stream this frame is for. Certain frames
168
// are not stream-specific, in which case this field is 0.
172
// Header returns h. It exists so FrameHeaders can be embedded in other
173
// specific frame types and implement the Frame interface.
174
func (h FrameHeader) Header() FrameHeader { return h }
176
func (h FrameHeader) String() string {
178
buf.WriteString("[FrameHeader ")
184
func (h FrameHeader) writeDebug(buf *bytes.Buffer) {
185
buf.WriteString(h.Type.String())
187
buf.WriteString(" flags=")
189
for i := uint8(0); i < 8; i++ {
190
if h.Flags&(1<<i) == 0 {
197
name := flagName[h.Type][Flags(1<<i)]
199
buf.WriteString(name)
201
fmt.Fprintf(buf, "0x%x", 1<<i)
206
fmt.Fprintf(buf, " stream=%d", h.StreamID)
208
fmt.Fprintf(buf, " len=%d", h.Length)
211
func (h *FrameHeader) checkValid() {
213
panic("Frame accessor called on non-owned Frame")
217
func (h *FrameHeader) invalidate() { h.valid = false }
219
// frame header bytes.
220
// Used only by ReadFrameHeader.
221
var fhBytes = sync.Pool{
222
New: func() interface{} {
223
buf := make([]byte, frameHeaderLen)
228
// ReadFrameHeader reads 9 bytes from r and returns a FrameHeader.
229
// Most users should use Framer.ReadFrame instead.
230
func ReadFrameHeader(r io.Reader) (FrameHeader, error) {
231
bufp := fhBytes.Get().(*[]byte)
232
defer fhBytes.Put(bufp)
233
return readFrameHeader(*bufp, r)
236
func readFrameHeader(buf []byte, r io.Reader) (FrameHeader, error) {
237
_, err := io.ReadFull(r, buf[:frameHeaderLen])
239
return FrameHeader{}, err
242
Length: (uint32(buf[0])<<16 | uint32(buf[1])<<8 | uint32(buf[2])),
243
Type: FrameType(buf[3]),
244
Flags: Flags(buf[4]),
245
StreamID: binary.BigEndian.Uint32(buf[5:]) & (1<<31 - 1),
250
// A Frame is the base interface implemented by all frame types.
251
// Callers will generally type-assert the specific frame type:
252
// *HeadersFrame, *SettingsFrame, *WindowUpdateFrame, etc.
254
// Frames are only valid until the next call to Framer.ReadFrame.
255
type Frame interface {
258
// invalidate is called by Framer.ReadFrame to make this
259
// frame's buffers as being invalid, since the subsequent
260
// frame will reuse them.
264
// A Framer reads and writes Frames.
270
// countError is a non-nil func that's called on a frame parse
271
// error with some unique error path token. It's initialized
272
// from Transport.CountError or Server.CountError.
273
countError func(errToken string)
275
// lastHeaderStream is non-zero if the last frame was an
276
// unfinished HEADERS/CONTINUATION.
277
lastHeaderStream uint32
280
headerBuf [frameHeaderLen]byte
282
// TODO: let getReadBuf be configurable, and use a less memory-pinning
283
// allocator in server.go to minimize memory pinned for many idle conns.
284
// Will probably also need to make frame invalidation have a hook too.
285
getReadBuf func(size uint32) []byte
286
readBuf []byte // cache for default getReadBuf
288
maxWriteSize uint32 // zero means unlimited; TODO: implement
293
// AllowIllegalWrites permits the Framer's Write methods to
294
// write frames that do not conform to the HTTP/2 spec. This
295
// permits using the Framer to test other HTTP/2
296
// implementations' conformance to the spec.
297
// If false, the Write methods will prefer to return an error
298
// rather than comply.
299
AllowIllegalWrites bool
301
// AllowIllegalReads permits the Framer's ReadFrame method
302
// to return non-compliant frames or frame orders.
303
// This is for testing and permits using the Framer to test
304
// other HTTP/2 implementations' conformance to the spec.
305
// It is not compatible with ReadMetaHeaders.
306
AllowIllegalReads bool
308
// ReadMetaHeaders if non-nil causes ReadFrame to merge
309
// HEADERS and CONTINUATION frames together and return
310
// MetaHeadersFrame instead.
311
ReadMetaHeaders *hpack.Decoder
313
// MaxHeaderListSize is the http2 MAX_HEADER_LIST_SIZE.
314
// It's used only if ReadMetaHeaders is set; 0 means a sane default
316
// If the limit is hit, MetaHeadersFrame.Truncated is set true.
317
MaxHeaderListSize uint32
319
// TODO: track which type of frame & with which flags was sent
320
// last. Then return an error (unless AllowIllegalWrites) if
321
// we're in the middle of a header block and a
322
// non-Continuation or Continuation on a different stream is
323
// attempted to be written.
325
logReads, logWrites bool
327
debugFramer *Framer // only use for logging written writes
328
debugFramerBuf *bytes.Buffer
329
debugReadLoggerf func(string, ...interface{})
330
debugWriteLoggerf func(string, ...interface{})
332
frameCache *frameCache // nil if frames aren't reused (default)
335
func (fr *Framer) maxHeaderListSize() uint32 {
336
if fr.MaxHeaderListSize == 0 {
337
return 16 << 20 // sane default, per docs
339
return fr.MaxHeaderListSize
342
func (f *Framer) startWrite(ftype FrameType, flags Flags, streamID uint32) {
343
// Write the FrameHeader.
344
f.wbuf = append(f.wbuf[:0],
345
0, // 3 bytes of length, filled in in endWrite
356
func (f *Framer) endWrite() error {
357
// Now that we know the final size, fill in the FrameHeader in
358
// the space previously reserved for it. Abuse append.
359
length := len(f.wbuf) - frameHeaderLen
360
if length >= (1 << 24) {
361
return ErrFrameTooLarge
363
_ = append(f.wbuf[:0],
371
n, err := f.w.Write(f.wbuf)
372
if err == nil && n != len(f.wbuf) {
373
err = io.ErrShortWrite
378
func (f *Framer) logWrite() {
379
if f.debugFramer == nil {
380
f.debugFramerBuf = new(bytes.Buffer)
381
f.debugFramer = NewFramer(nil, f.debugFramerBuf)
382
f.debugFramer.logReads = false // we log it ourselves, saying "wrote" below
383
// Let us read anything, even if we accidentally wrote it
384
// in the wrong order:
385
f.debugFramer.AllowIllegalReads = true
387
f.debugFramerBuf.Write(f.wbuf)
388
fr, err := f.debugFramer.ReadFrame()
390
f.debugWriteLoggerf("http2: Framer %p: failed to decode just-written frame", f)
393
f.debugWriteLoggerf("http2: Framer %p: wrote %v", f, summarizeFrame(fr))
396
func (f *Framer) writeByte(v byte) { f.wbuf = append(f.wbuf, v) }
397
func (f *Framer) writeBytes(v []byte) { f.wbuf = append(f.wbuf, v...) }
398
func (f *Framer) writeUint16(v uint16) { f.wbuf = append(f.wbuf, byte(v>>8), byte(v)) }
399
func (f *Framer) writeUint32(v uint32) {
400
f.wbuf = append(f.wbuf, byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
404
minMaxFrameSize = 1 << 14
405
maxFrameSize = 1<<24 - 1
408
// SetReuseFrames allows the Framer to reuse Frames.
409
// If called on a Framer, Frames returned by calls to ReadFrame are only
410
// valid until the next call to ReadFrame.
411
func (fr *Framer) SetReuseFrames() {
412
if fr.frameCache != nil {
415
fr.frameCache = &frameCache{}
418
type frameCache struct {
422
func (fc *frameCache) getDataFrame() *DataFrame {
429
// NewFramer returns a Framer that writes frames to w and reads them from r.
430
func NewFramer(w io.Writer, r io.Reader) *Framer {
434
countError: func(string) {},
435
logReads: logFrameReads,
436
logWrites: logFrameWrites,
437
debugReadLoggerf: log.Printf,
438
debugWriteLoggerf: log.Printf,
440
fr.getReadBuf = func(size uint32) []byte {
441
if cap(fr.readBuf) >= int(size) {
442
return fr.readBuf[:size]
444
fr.readBuf = make([]byte, size)
447
fr.SetMaxReadFrameSize(maxFrameSize)
451
// SetMaxReadFrameSize sets the maximum size of a frame
452
// that will be read by a subsequent call to ReadFrame.
453
// It is the caller's responsibility to advertise this
454
// limit with a SETTINGS frame.
455
func (fr *Framer) SetMaxReadFrameSize(v uint32) {
456
if v > maxFrameSize {
462
// ErrorDetail returns a more detailed error of the last error
463
// returned by Framer.ReadFrame. For instance, if ReadFrame
464
// returns a StreamError with code PROTOCOL_ERROR, ErrorDetail
465
// will say exactly what was invalid. ErrorDetail is not guaranteed
466
// to return a non-nil value and like the rest of the http2 package,
467
// its return value is not protected by an API compatibility promise.
468
// ErrorDetail is reset after the next call to ReadFrame.
469
func (fr *Framer) ErrorDetail() error {
473
// ErrFrameTooLarge is returned from Framer.ReadFrame when the peer
474
// sends a frame that is larger than declared with SetMaxReadFrameSize.
475
var ErrFrameTooLarge = errors.New("http2: frame too large")
477
// terminalReadFrameError reports whether err is an unrecoverable
478
// error from ReadFrame and no other frames should be read.
479
func terminalReadFrameError(err error) bool {
480
if _, ok := err.(StreamError); ok {
486
// ReadFrame reads a single frame. The returned Frame is only valid
487
// until the next call to ReadFrame.
489
// If the frame is larger than previously set with SetMaxReadFrameSize, the
490
// returned error is ErrFrameTooLarge. Other errors may be of type
491
// ConnectionError, StreamError, or anything else from the underlying
493
func (fr *Framer) ReadFrame() (Frame, error) {
495
if fr.lastFrame != nil {
496
fr.lastFrame.invalidate()
498
fh, err := readFrameHeader(fr.headerBuf[:], fr.r)
502
if fh.Length > fr.maxReadSize {
503
return nil, ErrFrameTooLarge
505
payload := fr.getReadBuf(fh.Length)
506
if _, err := io.ReadFull(fr.r, payload); err != nil {
509
f, err := typeFrameParser(fh.Type)(fr.frameCache, fh, fr.countError, payload)
511
if ce, ok := err.(connError); ok {
512
return nil, fr.connError(ce.Code, ce.Reason)
516
if err := fr.checkFrameOrder(f); err != nil {
520
fr.debugReadLoggerf("http2: Framer %p: read %v", fr, summarizeFrame(f))
522
if fh.Type == FrameHeaders && fr.ReadMetaHeaders != nil {
523
return fr.readMetaFrame(f.(*HeadersFrame))
528
// connError returns ConnectionError(code) but first
529
// stashes away a public reason to the caller can optionally relay it
530
// to the peer before hanging up on them. This might help others debug
531
// their implementations.
532
func (fr *Framer) connError(code ErrCode, reason string) error {
533
fr.errDetail = errors.New(reason)
534
return ConnectionError(code)
537
// checkFrameOrder reports an error if f is an invalid frame to return
538
// next from ReadFrame. Mostly it checks whether HEADERS and
539
// CONTINUATION frames are contiguous.
540
func (fr *Framer) checkFrameOrder(f Frame) error {
543
if fr.AllowIllegalReads {
548
if fr.lastHeaderStream != 0 {
549
if fh.Type != FrameContinuation {
550
return fr.connError(ErrCodeProtocol,
551
fmt.Sprintf("got %s for stream %d; expected CONTINUATION following %s for stream %d",
552
fh.Type, fh.StreamID,
553
last.Header().Type, fr.lastHeaderStream))
555
if fh.StreamID != fr.lastHeaderStream {
556
return fr.connError(ErrCodeProtocol,
557
fmt.Sprintf("got CONTINUATION for stream %d; expected stream %d",
558
fh.StreamID, fr.lastHeaderStream))
560
} else if fh.Type == FrameContinuation {
561
return fr.connError(ErrCodeProtocol, fmt.Sprintf("unexpected CONTINUATION for stream %d", fh.StreamID))
565
case FrameHeaders, FrameContinuation:
566
if fh.Flags.Has(FlagHeadersEndHeaders) {
567
fr.lastHeaderStream = 0
569
fr.lastHeaderStream = fh.StreamID
576
// A DataFrame conveys arbitrary, variable-length sequences of octets
577
// associated with a stream.
578
// See https://httpwg.org/specs/rfc7540.html#rfc.section.6.1
579
type DataFrame struct {
584
func (f *DataFrame) StreamEnded() bool {
585
return f.FrameHeader.Flags.Has(FlagDataEndStream)
588
// Data returns the frame's data octets, not including any padding
589
// size byte or padding suffix bytes.
590
// The caller must not retain the returned memory past the next
592
func (f *DataFrame) Data() []byte {
597
func parseDataFrame(fc *frameCache, fh FrameHeader, countError func(string), payload []byte) (Frame, error) {
598
if fh.StreamID == 0 {
599
// DATA frames MUST be associated with a stream. If a
600
// DATA frame is received whose stream identifier
601
// field is 0x0, the recipient MUST respond with a
602
// connection error (Section 5.4.1) of type
604
countError("frame_data_stream_0")
605
return nil, connError{ErrCodeProtocol, "DATA frame with stream ID 0"}
607
f := fc.getDataFrame()
611
if fh.Flags.Has(FlagDataPadded) {
613
payload, padSize, err = readByte(payload)
615
countError("frame_data_pad_byte_short")
619
if int(padSize) > len(payload) {
620
// If the length of the padding is greater than the
621
// length of the frame payload, the recipient MUST
622
// treat this as a connection error.
623
// Filed: https://github.com/http2/http2-spec/issues/610
624
countError("frame_data_pad_too_big")
625
return nil, connError{ErrCodeProtocol, "pad size larger than data payload"}
627
f.data = payload[:len(payload)-int(padSize)]
632
errStreamID = errors.New("invalid stream ID")
633
errDepStreamID = errors.New("invalid dependent stream ID")
634
errPadLength = errors.New("pad length too large")
635
errPadBytes = errors.New("padding bytes must all be zeros unless AllowIllegalWrites is enabled")
638
func validStreamIDOrZero(streamID uint32) bool {
639
return streamID&(1<<31) == 0
642
func validStreamID(streamID uint32) bool {
643
return streamID != 0 && streamID&(1<<31) == 0
646
// WriteData writes a DATA frame.
648
// It will perform exactly one Write to the underlying Writer.
649
// It is the caller's responsibility not to violate the maximum frame size
650
// and to not call other Write methods concurrently.
651
func (f *Framer) WriteData(streamID uint32, endStream bool, data []byte) error {
652
return f.WriteDataPadded(streamID, endStream, data, nil)
655
// WriteDataPadded writes a DATA frame with optional padding.
657
// If pad is nil, the padding bit is not sent.
658
// The length of pad must not exceed 255 bytes.
659
// The bytes of pad must all be zero, unless f.AllowIllegalWrites is set.
661
// It will perform exactly one Write to the underlying Writer.
662
// It is the caller's responsibility not to violate the maximum frame size
663
// and to not call other Write methods concurrently.
664
func (f *Framer) WriteDataPadded(streamID uint32, endStream bool, data, pad []byte) error {
665
if err := f.startWriteDataPadded(streamID, endStream, data, pad); err != nil {
671
// startWriteDataPadded is WriteDataPadded, but only writes the frame to the Framer's internal buffer.
672
// The caller should call endWrite to flush the frame to the underlying writer.
673
func (f *Framer) startWriteDataPadded(streamID uint32, endStream bool, data, pad []byte) error {
674
if !validStreamID(streamID) && !f.AllowIllegalWrites {
681
if !f.AllowIllegalWrites {
682
for _, b := range pad {
684
// "Padding octets MUST be set to zero when sending."
692
flags |= FlagDataEndStream
695
flags |= FlagDataPadded
697
f.startWrite(FrameData, flags, streamID)
699
f.wbuf = append(f.wbuf, byte(len(pad)))
701
f.wbuf = append(f.wbuf, data...)
702
f.wbuf = append(f.wbuf, pad...)
706
// A SettingsFrame conveys configuration parameters that affect how
707
// endpoints communicate, such as preferences and constraints on peer
710
// See https://httpwg.org/specs/rfc7540.html#SETTINGS
711
type SettingsFrame struct {
716
func parseSettingsFrame(_ *frameCache, fh FrameHeader, countError func(string), p []byte) (Frame, error) {
717
if fh.Flags.Has(FlagSettingsAck) && fh.Length > 0 {
718
// When this (ACK 0x1) bit is set, the payload of the
719
// SETTINGS frame MUST be empty. Receipt of a
720
// SETTINGS frame with the ACK flag set and a length
721
// field value other than 0 MUST be treated as a
722
// connection error (Section 5.4.1) of type
724
countError("frame_settings_ack_with_length")
725
return nil, ConnectionError(ErrCodeFrameSize)
727
if fh.StreamID != 0 {
728
// SETTINGS frames always apply to a connection,
729
// never a single stream. The stream identifier for a
730
// SETTINGS frame MUST be zero (0x0). If an endpoint
731
// receives a SETTINGS frame whose stream identifier
732
// field is anything other than 0x0, the endpoint MUST
733
// respond with a connection error (Section 5.4.1) of
734
// type PROTOCOL_ERROR.
735
countError("frame_settings_has_stream")
736
return nil, ConnectionError(ErrCodeProtocol)
739
countError("frame_settings_mod_6")
740
// Expecting even number of 6 byte settings.
741
return nil, ConnectionError(ErrCodeFrameSize)
743
f := &SettingsFrame{FrameHeader: fh, p: p}
744
if v, ok := f.Value(SettingInitialWindowSize); ok && v > (1<<31)-1 {
745
countError("frame_settings_window_size_too_big")
746
// Values above the maximum flow control window size of 2^31 - 1 MUST
747
// be treated as a connection error (Section 5.4.1) of type
748
// FLOW_CONTROL_ERROR.
749
return nil, ConnectionError(ErrCodeFlowControl)
754
func (f *SettingsFrame) IsAck() bool {
755
return f.FrameHeader.Flags.Has(FlagSettingsAck)
758
func (f *SettingsFrame) Value(id SettingID) (v uint32, ok bool) {
760
for i := 0; i < f.NumSettings(); i++ {
761
if s := f.Setting(i); s.ID == id {
768
// Setting returns the setting from the frame at the given 0-based index.
769
// The index must be >= 0 and less than f.NumSettings().
770
func (f *SettingsFrame) Setting(i int) Setting {
773
ID: SettingID(binary.BigEndian.Uint16(buf[i*6 : i*6+2])),
774
Val: binary.BigEndian.Uint32(buf[i*6+2 : i*6+6]),
778
func (f *SettingsFrame) NumSettings() int { return len(f.p) / 6 }
780
// HasDuplicates reports whether f contains any duplicate setting IDs.
781
func (f *SettingsFrame) HasDuplicates() bool {
782
num := f.NumSettings()
786
// If it's small enough (the common case), just do the n^2
787
// thing and avoid a map allocation.
789
for i := 0; i < num; i++ {
790
idi := f.Setting(i).ID
791
for j := i + 1; j < num; j++ {
792
idj := f.Setting(j).ID
800
seen := map[SettingID]bool{}
801
for i := 0; i < num; i++ {
802
id := f.Setting(i).ID
811
// ForeachSetting runs fn for each setting.
812
// It stops and returns the first error.
813
func (f *SettingsFrame) ForeachSetting(fn func(Setting) error) error {
815
for i := 0; i < f.NumSettings(); i++ {
816
if err := fn(f.Setting(i)); err != nil {
823
// WriteSettings writes a SETTINGS frame with zero or more settings
824
// specified and the ACK bit not set.
826
// It will perform exactly one Write to the underlying Writer.
827
// It is the caller's responsibility to not call other Write methods concurrently.
828
func (f *Framer) WriteSettings(settings ...Setting) error {
829
f.startWrite(FrameSettings, 0, 0)
830
for _, s := range settings {
831
f.writeUint16(uint16(s.ID))
837
// WriteSettingsAck writes an empty SETTINGS frame with the ACK bit set.
839
// It will perform exactly one Write to the underlying Writer.
840
// It is the caller's responsibility to not call other Write methods concurrently.
841
func (f *Framer) WriteSettingsAck() error {
842
f.startWrite(FrameSettings, FlagSettingsAck, 0)
846
// A PingFrame is a mechanism for measuring a minimal round trip time
847
// from the sender, as well as determining whether an idle connection
848
// is still functional.
849
// See https://httpwg.org/specs/rfc7540.html#rfc.section.6.7
850
type PingFrame struct {
855
func (f *PingFrame) IsAck() bool { return f.Flags.Has(FlagPingAck) }
857
func parsePingFrame(_ *frameCache, fh FrameHeader, countError func(string), payload []byte) (Frame, error) {
858
if len(payload) != 8 {
859
countError("frame_ping_length")
860
return nil, ConnectionError(ErrCodeFrameSize)
862
if fh.StreamID != 0 {
863
countError("frame_ping_has_stream")
864
return nil, ConnectionError(ErrCodeProtocol)
866
f := &PingFrame{FrameHeader: fh}
867
copy(f.Data[:], payload)
871
func (f *Framer) WritePing(ack bool, data [8]byte) error {
876
f.startWrite(FramePing, flags, 0)
877
f.writeBytes(data[:])
881
// A GoAwayFrame informs the remote peer to stop creating streams on this connection.
882
// See https://httpwg.org/specs/rfc7540.html#rfc.section.6.8
883
type GoAwayFrame struct {
890
// DebugData returns any debug data in the GOAWAY frame. Its contents
892
// The caller must not retain the returned memory past the next
894
func (f *GoAwayFrame) DebugData() []byte {
899
func parseGoAwayFrame(_ *frameCache, fh FrameHeader, countError func(string), p []byte) (Frame, error) {
900
if fh.StreamID != 0 {
901
countError("frame_goaway_has_stream")
902
return nil, ConnectionError(ErrCodeProtocol)
905
countError("frame_goaway_short")
906
return nil, ConnectionError(ErrCodeFrameSize)
910
LastStreamID: binary.BigEndian.Uint32(p[:4]) & (1<<31 - 1),
911
ErrCode: ErrCode(binary.BigEndian.Uint32(p[4:8])),
916
func (f *Framer) WriteGoAway(maxStreamID uint32, code ErrCode, debugData []byte) error {
917
f.startWrite(FrameGoAway, 0, 0)
918
f.writeUint32(maxStreamID & (1<<31 - 1))
919
f.writeUint32(uint32(code))
920
f.writeBytes(debugData)
924
// An UnknownFrame is the frame type returned when the frame type is unknown
925
// or no specific frame type parser exists.
926
type UnknownFrame struct {
931
// Payload returns the frame's payload (after the header). It is not
932
// valid to call this method after a subsequent call to
933
// Framer.ReadFrame, nor is it valid to retain the returned slice.
934
// The memory is owned by the Framer and is invalidated when the next
936
func (f *UnknownFrame) Payload() []byte {
941
func parseUnknownFrame(_ *frameCache, fh FrameHeader, countError func(string), p []byte) (Frame, error) {
942
return &UnknownFrame{fh, p}, nil
945
// A WindowUpdateFrame is used to implement flow control.
946
// See https://httpwg.org/specs/rfc7540.html#rfc.section.6.9
947
type WindowUpdateFrame struct {
949
Increment uint32 // never read with high bit set
952
func parseWindowUpdateFrame(_ *frameCache, fh FrameHeader, countError func(string), p []byte) (Frame, error) {
954
countError("frame_windowupdate_bad_len")
955
return nil, ConnectionError(ErrCodeFrameSize)
957
inc := binary.BigEndian.Uint32(p[:4]) & 0x7fffffff // mask off high reserved bit
959
// A receiver MUST treat the receipt of a
960
// WINDOW_UPDATE frame with an flow control window
961
// increment of 0 as a stream error (Section 5.4.2) of
962
// type PROTOCOL_ERROR; errors on the connection flow
963
// control window MUST be treated as a connection
964
// error (Section 5.4.1).
965
if fh.StreamID == 0 {
966
countError("frame_windowupdate_zero_inc_conn")
967
return nil, ConnectionError(ErrCodeProtocol)
969
countError("frame_windowupdate_zero_inc_stream")
970
return nil, streamError(fh.StreamID, ErrCodeProtocol)
972
return &WindowUpdateFrame{
978
// WriteWindowUpdate writes a WINDOW_UPDATE frame.
979
// The increment value must be between 1 and 2,147,483,647, inclusive.
980
// If the Stream ID is zero, the window update applies to the
981
// connection as a whole.
982
func (f *Framer) WriteWindowUpdate(streamID, incr uint32) error {
983
// "The legal range for the increment to the flow control window is 1 to 2^31-1 (2,147,483,647) octets."
984
if (incr < 1 || incr > 2147483647) && !f.AllowIllegalWrites {
985
return errors.New("illegal window increment value")
987
f.startWrite(FrameWindowUpdate, 0, streamID)
992
// A HeadersFrame is used to open a stream and additionally carries a
993
// header block fragment.
994
type HeadersFrame struct {
997
// Priority is set if FlagHeadersPriority is set in the FrameHeader.
998
Priority PriorityParam
1000
headerFragBuf []byte // not owned
1003
func (f *HeadersFrame) HeaderBlockFragment() []byte {
1005
return f.headerFragBuf
1008
func (f *HeadersFrame) HeadersEnded() bool {
1009
return f.FrameHeader.Flags.Has(FlagHeadersEndHeaders)
1012
func (f *HeadersFrame) StreamEnded() bool {
1013
return f.FrameHeader.Flags.Has(FlagHeadersEndStream)
1016
func (f *HeadersFrame) HasPriority() bool {
1017
return f.FrameHeader.Flags.Has(FlagHeadersPriority)
1020
func parseHeadersFrame(_ *frameCache, fh FrameHeader, countError func(string), p []byte) (_ Frame, err error) {
1021
hf := &HeadersFrame{
1024
if fh.StreamID == 0 {
1025
// HEADERS frames MUST be associated with a stream. If a HEADERS frame
1026
// is received whose stream identifier field is 0x0, the recipient MUST
1027
// respond with a connection error (Section 5.4.1) of type
1029
countError("frame_headers_zero_stream")
1030
return nil, connError{ErrCodeProtocol, "HEADERS frame with stream ID 0"}
1033
if fh.Flags.Has(FlagHeadersPadded) {
1034
if p, padLength, err = readByte(p); err != nil {
1035
countError("frame_headers_pad_short")
1039
if fh.Flags.Has(FlagHeadersPriority) {
1041
p, v, err = readUint32(p)
1043
countError("frame_headers_prio_short")
1046
hf.Priority.StreamDep = v & 0x7fffffff
1047
hf.Priority.Exclusive = (v != hf.Priority.StreamDep) // high bit was set
1048
p, hf.Priority.Weight, err = readByte(p)
1050
countError("frame_headers_prio_weight_short")
1054
if len(p)-int(padLength) < 0 {
1055
countError("frame_headers_pad_too_big")
1056
return nil, streamError(fh.StreamID, ErrCodeProtocol)
1058
hf.headerFragBuf = p[:len(p)-int(padLength)]
1062
// HeadersFrameParam are the parameters for writing a HEADERS frame.
1063
type HeadersFrameParam struct {
1064
// StreamID is the required Stream ID to initiate.
1066
// BlockFragment is part (or all) of a Header Block.
1067
BlockFragment []byte
1069
// EndStream indicates that the header block is the last that
1070
// the endpoint will send for the identified stream. Setting
1071
// this flag causes the stream to enter one of "half closed"
1075
// EndHeaders indicates that this frame contains an entire
1076
// header block and is not followed by any
1077
// CONTINUATION frames.
1080
// PadLength is the optional number of bytes of zeros to add
1084
// Priority, if non-zero, includes stream priority information
1085
// in the HEADER frame.
1086
Priority PriorityParam
1089
// WriteHeaders writes a single HEADERS frame.
1091
// This is a low-level header writing method. Encoding headers and
1092
// splitting them into any necessary CONTINUATION frames is handled
1095
// It will perform exactly one Write to the underlying Writer.
1096
// It is the caller's responsibility to not call other Write methods concurrently.
1097
func (f *Framer) WriteHeaders(p HeadersFrameParam) error {
1098
if !validStreamID(p.StreamID) && !f.AllowIllegalWrites {
1102
if p.PadLength != 0 {
1103
flags |= FlagHeadersPadded
1106
flags |= FlagHeadersEndStream
1109
flags |= FlagHeadersEndHeaders
1111
if !p.Priority.IsZero() {
1112
flags |= FlagHeadersPriority
1114
f.startWrite(FrameHeaders, flags, p.StreamID)
1115
if p.PadLength != 0 {
1116
f.writeByte(p.PadLength)
1118
if !p.Priority.IsZero() {
1119
v := p.Priority.StreamDep
1120
if !validStreamIDOrZero(v) && !f.AllowIllegalWrites {
1121
return errDepStreamID
1123
if p.Priority.Exclusive {
1127
f.writeByte(p.Priority.Weight)
1129
f.wbuf = append(f.wbuf, p.BlockFragment...)
1130
f.wbuf = append(f.wbuf, padZeros[:p.PadLength]...)
1134
// A PriorityFrame specifies the sender-advised priority of a stream.
1135
// See https://httpwg.org/specs/rfc7540.html#rfc.section.6.3
1136
type PriorityFrame struct {
1141
// PriorityParam are the stream prioritzation parameters.
1142
type PriorityParam struct {
1143
// StreamDep is a 31-bit stream identifier for the
1144
// stream that this stream depends on. Zero means no
1148
// Exclusive is whether the dependency is exclusive.
1151
// Weight is the stream's zero-indexed weight. It should be
1152
// set together with StreamDep, or neither should be set. Per
1153
// the spec, "Add one to the value to obtain a weight between
1158
func (p PriorityParam) IsZero() bool {
1159
return p == PriorityParam{}
1162
func parsePriorityFrame(_ *frameCache, fh FrameHeader, countError func(string), payload []byte) (Frame, error) {
1163
if fh.StreamID == 0 {
1164
countError("frame_priority_zero_stream")
1165
return nil, connError{ErrCodeProtocol, "PRIORITY frame with stream ID 0"}
1167
if len(payload) != 5 {
1168
countError("frame_priority_bad_length")
1169
return nil, connError{ErrCodeFrameSize, fmt.Sprintf("PRIORITY frame payload size was %d; want 5", len(payload))}
1171
v := binary.BigEndian.Uint32(payload[:4])
1172
streamID := v & 0x7fffffff // mask off high bit
1173
return &PriorityFrame{
1175
PriorityParam: PriorityParam{
1177
StreamDep: streamID,
1178
Exclusive: streamID != v, // was high bit set?
1183
// WritePriority writes a PRIORITY frame.
1185
// It will perform exactly one Write to the underlying Writer.
1186
// It is the caller's responsibility to not call other Write methods concurrently.
1187
func (f *Framer) WritePriority(streamID uint32, p PriorityParam) error {
1188
if !validStreamID(streamID) && !f.AllowIllegalWrites {
1191
if !validStreamIDOrZero(p.StreamDep) {
1192
return errDepStreamID
1194
f.startWrite(FramePriority, 0, streamID)
1200
f.writeByte(p.Weight)
1204
// A RSTStreamFrame allows for abnormal termination of a stream.
1205
// See https://httpwg.org/specs/rfc7540.html#rfc.section.6.4
1206
type RSTStreamFrame struct {
1211
func parseRSTStreamFrame(_ *frameCache, fh FrameHeader, countError func(string), p []byte) (Frame, error) {
1213
countError("frame_rststream_bad_len")
1214
return nil, ConnectionError(ErrCodeFrameSize)
1216
if fh.StreamID == 0 {
1217
countError("frame_rststream_zero_stream")
1218
return nil, ConnectionError(ErrCodeProtocol)
1220
return &RSTStreamFrame{fh, ErrCode(binary.BigEndian.Uint32(p[:4]))}, nil
1223
// WriteRSTStream writes a RST_STREAM frame.
1225
// It will perform exactly one Write to the underlying Writer.
1226
// It is the caller's responsibility to not call other Write methods concurrently.
1227
func (f *Framer) WriteRSTStream(streamID uint32, code ErrCode) error {
1228
if !validStreamID(streamID) && !f.AllowIllegalWrites {
1231
f.startWrite(FrameRSTStream, 0, streamID)
1232
f.writeUint32(uint32(code))
1236
// A ContinuationFrame is used to continue a sequence of header block fragments.
1237
// See https://httpwg.org/specs/rfc7540.html#rfc.section.6.10
1238
type ContinuationFrame struct {
1240
headerFragBuf []byte
1243
func parseContinuationFrame(_ *frameCache, fh FrameHeader, countError func(string), p []byte) (Frame, error) {
1244
if fh.StreamID == 0 {
1245
countError("frame_continuation_zero_stream")
1246
return nil, connError{ErrCodeProtocol, "CONTINUATION frame with stream ID 0"}
1248
return &ContinuationFrame{fh, p}, nil
1251
func (f *ContinuationFrame) HeaderBlockFragment() []byte {
1253
return f.headerFragBuf
1256
func (f *ContinuationFrame) HeadersEnded() bool {
1257
return f.FrameHeader.Flags.Has(FlagContinuationEndHeaders)
1260
// WriteContinuation writes a CONTINUATION frame.
1262
// It will perform exactly one Write to the underlying Writer.
1263
// It is the caller's responsibility to not call other Write methods concurrently.
1264
func (f *Framer) WriteContinuation(streamID uint32, endHeaders bool, headerBlockFragment []byte) error {
1265
if !validStreamID(streamID) && !f.AllowIllegalWrites {
1270
flags |= FlagContinuationEndHeaders
1272
f.startWrite(FrameContinuation, flags, streamID)
1273
f.wbuf = append(f.wbuf, headerBlockFragment...)
1277
// A PushPromiseFrame is used to initiate a server stream.
1278
// See https://httpwg.org/specs/rfc7540.html#rfc.section.6.6
1279
type PushPromiseFrame struct {
1282
headerFragBuf []byte // not owned
1285
func (f *PushPromiseFrame) HeaderBlockFragment() []byte {
1287
return f.headerFragBuf
1290
func (f *PushPromiseFrame) HeadersEnded() bool {
1291
return f.FrameHeader.Flags.Has(FlagPushPromiseEndHeaders)
1294
func parsePushPromise(_ *frameCache, fh FrameHeader, countError func(string), p []byte) (_ Frame, err error) {
1295
pp := &PushPromiseFrame{
1298
if pp.StreamID == 0 {
1299
// PUSH_PROMISE frames MUST be associated with an existing,
1300
// peer-initiated stream. The stream identifier of a
1301
// PUSH_PROMISE frame indicates the stream it is associated
1302
// with. If the stream identifier field specifies the value
1303
// 0x0, a recipient MUST respond with a connection error
1304
// (Section 5.4.1) of type PROTOCOL_ERROR.
1305
countError("frame_pushpromise_zero_stream")
1306
return nil, ConnectionError(ErrCodeProtocol)
1308
// The PUSH_PROMISE frame includes optional padding.
1309
// Padding fields and flags are identical to those defined for DATA frames
1311
if fh.Flags.Has(FlagPushPromisePadded) {
1312
if p, padLength, err = readByte(p); err != nil {
1313
countError("frame_pushpromise_pad_short")
1318
p, pp.PromiseID, err = readUint32(p)
1320
countError("frame_pushpromise_promiseid_short")
1323
pp.PromiseID = pp.PromiseID & (1<<31 - 1)
1325
if int(padLength) > len(p) {
1326
// like the DATA frame, error out if padding is longer than the body.
1327
countError("frame_pushpromise_pad_too_big")
1328
return nil, ConnectionError(ErrCodeProtocol)
1330
pp.headerFragBuf = p[:len(p)-int(padLength)]
1334
// PushPromiseParam are the parameters for writing a PUSH_PROMISE frame.
1335
type PushPromiseParam struct {
1336
// StreamID is the required Stream ID to initiate.
1339
// PromiseID is the required Stream ID which this
1343
// BlockFragment is part (or all) of a Header Block.
1344
BlockFragment []byte
1346
// EndHeaders indicates that this frame contains an entire
1347
// header block and is not followed by any
1348
// CONTINUATION frames.
1351
// PadLength is the optional number of bytes of zeros to add
1356
// WritePushPromise writes a single PushPromise Frame.
1358
// As with Header Frames, This is the low level call for writing
1359
// individual frames. Continuation frames are handled elsewhere.
1361
// It will perform exactly one Write to the underlying Writer.
1362
// It is the caller's responsibility to not call other Write methods concurrently.
1363
func (f *Framer) WritePushPromise(p PushPromiseParam) error {
1364
if !validStreamID(p.StreamID) && !f.AllowIllegalWrites {
1368
if p.PadLength != 0 {
1369
flags |= FlagPushPromisePadded
1372
flags |= FlagPushPromiseEndHeaders
1374
f.startWrite(FramePushPromise, flags, p.StreamID)
1375
if p.PadLength != 0 {
1376
f.writeByte(p.PadLength)
1378
if !validStreamID(p.PromiseID) && !f.AllowIllegalWrites {
1381
f.writeUint32(p.PromiseID)
1382
f.wbuf = append(f.wbuf, p.BlockFragment...)
1383
f.wbuf = append(f.wbuf, padZeros[:p.PadLength]...)
1387
// WriteRawFrame writes a raw frame. This can be used to write
1388
// extension frames unknown to this package.
1389
func (f *Framer) WriteRawFrame(t FrameType, flags Flags, streamID uint32, payload []byte) error {
1390
f.startWrite(t, flags, streamID)
1391
f.writeBytes(payload)
1395
func readByte(p []byte) (remain []byte, b byte, err error) {
1397
return nil, 0, io.ErrUnexpectedEOF
1399
return p[1:], p[0], nil
1402
func readUint32(p []byte) (remain []byte, v uint32, err error) {
1404
return nil, 0, io.ErrUnexpectedEOF
1406
return p[4:], binary.BigEndian.Uint32(p[:4]), nil
1409
type streamEnder interface {
1413
type headersEnder interface {
1417
type headersOrContinuation interface {
1419
HeaderBlockFragment() []byte
1422
// A MetaHeadersFrame is the representation of one HEADERS frame and
1423
// zero or more contiguous CONTINUATION frames and the decoding of
1424
// their HPACK-encoded contents.
1426
// This type of frame does not appear on the wire and is only returned
1427
// by the Framer when Framer.ReadMetaHeaders is set.
1428
type MetaHeadersFrame struct {
1431
// Fields are the fields contained in the HEADERS and
1432
// CONTINUATION frames. The underlying slice is owned by the
1433
// Framer and must not be retained after the next call to
1436
// Fields are guaranteed to be in the correct http2 order and
1437
// not have unknown pseudo header fields or invalid header
1438
// field names or values. Required pseudo header fields may be
1439
// missing, however. Use the MetaHeadersFrame.Pseudo accessor
1440
// method access pseudo headers.
1441
Fields []hpack.HeaderField
1443
// Truncated is whether the max header list size limit was hit
1444
// and Fields is incomplete. The hpack decoder state is still
1449
// PseudoValue returns the given pseudo header field's value.
1450
// The provided pseudo field should not contain the leading colon.
1451
func (mh *MetaHeadersFrame) PseudoValue(pseudo string) string {
1452
for _, hf := range mh.Fields {
1456
if hf.Name[1:] == pseudo {
1463
// RegularFields returns the regular (non-pseudo) header fields of mh.
1464
// The caller does not own the returned slice.
1465
func (mh *MetaHeadersFrame) RegularFields() []hpack.HeaderField {
1466
for i, hf := range mh.Fields {
1468
return mh.Fields[i:]
1474
// PseudoFields returns the pseudo header fields of mh.
1475
// The caller does not own the returned slice.
1476
func (mh *MetaHeadersFrame) PseudoFields() []hpack.HeaderField {
1477
for i, hf := range mh.Fields {
1479
return mh.Fields[:i]
1485
func (mh *MetaHeadersFrame) checkPseudos() error {
1486
var isRequest, isResponse bool
1487
pf := mh.PseudoFields()
1488
for i, hf := range pf {
1490
case ":method", ":path", ":scheme", ":authority":
1495
return pseudoHeaderError(hf.Name)
1497
// Check for duplicates.
1498
// This would be a bad algorithm, but N is 4.
1499
// And this doesn't allocate.
1500
for _, hf2 := range pf[:i] {
1501
if hf.Name == hf2.Name {
1502
return duplicatePseudoHeaderError(hf.Name)
1506
if isRequest && isResponse {
1507
return errMixPseudoHeaderTypes
1512
func (fr *Framer) maxHeaderStringLen() int {
1513
v := int(fr.maxHeaderListSize())
1515
// If maxHeaderListSize overflows an int, use no limit (0).
1521
// readMetaFrame returns 0 or more CONTINUATION frames from fr and
1522
// merge them into the provided hf and returns a MetaHeadersFrame
1523
// with the decoded hpack values.
1524
func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
1525
if fr.AllowIllegalReads {
1526
return nil, errors.New("illegal use of AllowIllegalReads with ReadMetaHeaders")
1528
mh := &MetaHeadersFrame{
1531
var remainSize = fr.maxHeaderListSize()
1534
var invalid error // pseudo header field errors
1535
hdec := fr.ReadMetaHeaders
1536
hdec.SetEmitEnabled(true)
1537
hdec.SetMaxStringLength(fr.maxHeaderStringLen())
1538
hdec.SetEmitFunc(func(hf hpack.HeaderField) {
1539
if VerboseLogs && fr.logReads {
1540
fr.debugReadLoggerf("http2: decoded hpack field %+v", hf)
1542
if !httpguts.ValidHeaderFieldValue(hf.Value) {
1543
// Don't include the value in the error, because it may be sensitive.
1544
invalid = headerFieldValueError(hf.Name)
1546
isPseudo := strings.HasPrefix(hf.Name, ":")
1549
invalid = errPseudoAfterRegular
1553
if !validWireHeaderFieldName(hf.Name) {
1554
invalid = headerFieldNameError(hf.Name)
1559
hdec.SetEmitEnabled(false)
1564
if size > remainSize {
1565
hdec.SetEmitEnabled(false)
1572
mh.Fields = append(mh.Fields, hf)
1574
// Lose reference to MetaHeadersFrame:
1575
defer hdec.SetEmitFunc(func(hf hpack.HeaderField) {})
1577
var hc headersOrContinuation = hf
1579
frag := hc.HeaderBlockFragment()
1581
// Avoid parsing large amounts of headers that we will then discard.
1582
// If the sender exceeds the max header list size by too much,
1583
// skip parsing the fragment and close the connection.
1585
// "Too much" is either any CONTINUATION frame after we've already
1586
// exceeded the max header list size (in which case remainSize is 0),
1587
// or a frame whose encoded size is more than twice the remaining
1588
// header list bytes we're willing to accept.
1589
if int64(len(frag)) > int64(2*remainSize) {
1591
log.Printf("http2: header list too large")
1593
// It would be nice to send a RST_STREAM before sending the GOAWAY,
1594
// but the structure of the server's frame writer makes this difficult.
1595
return nil, ConnectionError(ErrCodeProtocol)
1598
// Also close the connection after any CONTINUATION frame following an
1599
// invalid header, since we stop tracking the size of the headers after
1603
log.Printf("http2: invalid header: %v", invalid)
1605
// It would be nice to send a RST_STREAM before sending the GOAWAY,
1606
// but the structure of the server's frame writer makes this difficult.
1607
return nil, ConnectionError(ErrCodeProtocol)
1610
if _, err := hdec.Write(frag); err != nil {
1611
return nil, ConnectionError(ErrCodeCompression)
1614
if hc.HeadersEnded() {
1617
if f, err := fr.ReadFrame(); err != nil {
1620
hc = f.(*ContinuationFrame) // guaranteed by checkFrameOrder
1624
mh.HeadersFrame.headerFragBuf = nil
1625
mh.HeadersFrame.invalidate()
1627
if err := hdec.Close(); err != nil {
1628
return nil, ConnectionError(ErrCodeCompression)
1631
fr.errDetail = invalid
1633
log.Printf("http2: invalid header: %v", invalid)
1635
return nil, StreamError{mh.StreamID, ErrCodeProtocol, invalid}
1637
if err := mh.checkPseudos(); err != nil {
1640
log.Printf("http2: invalid pseudo headers: %v", err)
1642
return nil, StreamError{mh.StreamID, ErrCodeProtocol, err}
1647
func summarizeFrame(f Frame) string {
1648
var buf bytes.Buffer
1649
f.Header().writeDebug(&buf)
1650
switch f := f.(type) {
1651
case *SettingsFrame:
1653
f.ForeachSetting(func(s Setting) error {
1656
buf.WriteString(", settings:")
1658
fmt.Fprintf(&buf, " %v=%v,", s.ID, s.Val)
1662
buf.Truncate(buf.Len() - 1) // remove trailing comma
1667
if len(data) > max {
1670
fmt.Fprintf(&buf, " data=%q", data)
1671
if len(f.Data()) > max {
1672
fmt.Fprintf(&buf, " (%d bytes omitted)", len(f.Data())-max)
1674
case *WindowUpdateFrame:
1675
if f.StreamID == 0 {
1676
buf.WriteString(" (conn)")
1678
fmt.Fprintf(&buf, " incr=%v", f.Increment)
1680
fmt.Fprintf(&buf, " ping=%q", f.Data[:])
1682
fmt.Fprintf(&buf, " LastStreamID=%v ErrCode=%v Debug=%q",
1683
f.LastStreamID, f.ErrCode, f.debugData)
1684
case *RSTStreamFrame:
1685
fmt.Fprintf(&buf, " ErrCode=%v", f.ErrCode)