Explorar el Código

http2: log frame reads at log level http2debug=2 also, not just writes

Change-Id: I259fb17d9cf14c11e4930d48d1657947404b6ada
Reviewed-on: https://go-review.googlesource.com/18474
Reviewed-by: Blake Mizerany <blake.mizerany@gmail.com>
Brad Fitzpatrick hace 10 años
padre
commit
c93a9b4f2a
Se han modificado 2 ficheros con 11 adiciones y 2 borrados
  1. 9 2
      http2/frame.go
  2. 2 0
      http2/http2.go

+ 9 - 2
http2/frame.go

@@ -301,6 +301,8 @@ type Framer struct {
 	// non-Continuation or Continuation on a different stream is
 	// attempted to be written.
 
+	logReads bool
+
 	debugFramer    *Framer // only use for logging written writes
 	debugFramerBuf *bytes.Buffer
 }
@@ -345,6 +347,7 @@ func (f *Framer) logWrite() {
 	if f.debugFramer == nil {
 		f.debugFramerBuf = new(bytes.Buffer)
 		f.debugFramer = NewFramer(nil, f.debugFramerBuf)
+		f.debugFramer.logReads = false // we log it ourselves, saying "wrote" below
 		// Let us read anything, even if we accidentally wrote it
 		// in the wrong order:
 		f.debugFramer.AllowIllegalReads = true
@@ -373,8 +376,9 @@ const (
 // NewFramer returns a Framer that writes frames to w and reads them from r.
 func NewFramer(w io.Writer, r io.Reader) *Framer {
 	fr := &Framer{
-		w: w,
-		r: r,
+		w:        w,
+		r:        r,
+		logReads: logFrameReads,
 	}
 	fr.getReadBuf = func(size uint32) []byte {
 		if cap(fr.readBuf) >= int(size) {
@@ -443,6 +447,9 @@ func (fr *Framer) ReadFrame() (Frame, error) {
 	if err := fr.checkFrameOrder(f); err != nil {
 		return nil, err
 	}
+	if fr.logReads {
+		log.Printf("http2: Framer %p: read %v", fr, summarizeFrame(f))
+	}
 	return f, nil
 }
 

+ 2 - 0
http2/http2.go

@@ -29,6 +29,7 @@ import (
 var (
 	VerboseLogs    bool
 	logFrameWrites bool
+	logFrameReads  bool
 )
 
 func init() {
@@ -39,6 +40,7 @@ func init() {
 	if strings.Contains(e, "http2debug=2") {
 		VerboseLogs = true
 		logFrameWrites = true
+		logFrameReads = true
 	}
 }