git » go-net » commit f6d2119

http2: add more HEADERS and error logging in GODEBUG=http2debug=2 mode

author Brad Fitzpatrick
2016-08-02 14:09:40 UTC
committer Brad Fitzpatrick
2016-08-02 14:27:26 UTC
parent 28d1bd4fbe7e56c9025ffe3a89113fa4f5e48f31

http2: add more HEADERS and error logging in GODEBUG=http2debug=2 mode

To help debug golang/go#16572

Change-Id: Ia154faedd243a06a4110f6e6a4885b7cd0a04e1f
Reviewed-on: https://go-review.googlesource.com/25401
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>

http2/frame.go +9 -0
http2/http2_test.go +1 -1

diff --git a/http2/frame.go b/http2/frame.go
index bd50d09..6769907 100644
--- a/http2/frame.go
+++ b/http2/frame.go
@@ -1419,6 +1419,9 @@ func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
 	hdec.SetEmitEnabled(true)
 	hdec.SetMaxStringLength(fr.maxHeaderStringLen())
 	hdec.SetEmitFunc(func(hf hpack.HeaderField) {
+		if VerboseLogs && logFrameReads {
+			log.Printf("http2: decoded hpack field %+v", hf)
+		}
 		if !httplex.ValidHeaderFieldValue(hf.Value) {
 			invalid = headerFieldValueError(hf.Value)
 		}
@@ -1477,10 +1480,16 @@ func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
 	}
 	if invalid != nil {
 		fr.errDetail = invalid
+		if VerboseLogs {
+			log.Printf("http2: invalid header: %v", invalid)
+		}
 		return nil, StreamError{mh.StreamID, ErrCodeProtocol}
 	}
 	if err := mh.checkPseudos(); err != nil {
 		fr.errDetail = err
+		if VerboseLogs {
+			log.Printf("http2: invalid pseudo headers: %v", err)
+		}
 		return nil, StreamError{mh.StreamID, ErrCodeProtocol}
 	}
 	return mh, nil
diff --git a/http2/http2_test.go b/http2/http2_test.go
index 549ff5e..22c2ace 100644
--- a/http2/http2_test.go
+++ b/http2/http2_test.go
@@ -28,7 +28,7 @@ func condSkipFailingTest(t *testing.T) {
 
 func init() {
 	DebugGoroutines = true
-	flag.BoolVar(&VerboseLogs, "verboseh2", false, "Verbose HTTP/2 debug logging")
+	flag.BoolVar(&VerboseLogs, "verboseh2", VerboseLogs, "Verbose HTTP/2 debug logging")
 }
 
 func TestSettingString(t *testing.T) {