Commit 9946ad7d authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

http2: quiet Transport logging

Add logf/vlogf helpers for Transport like the server side.

Change-Id: I9c9e5dc38c06118204da615c59de60cd3f9561ef
Reviewed-on: https://go-review.googlesource.com/16064Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
parent 56401056
......@@ -256,7 +256,7 @@ func (t *Transport) newClientConn(host, port, key string) (*clientConn, error) {
cc.initialWindowSize = s.Val
default:
// TODO(bradfitz): handle more
log.Printf("Unhandled Setting: %v", s)
t.vlogf("Unhandled Setting: %v", s)
}
return nil
})
......@@ -383,7 +383,6 @@ func (cc *clientConn) encodeHeaders(req *http.Request) []byte {
}
func (cc *clientConn) writeHeader(name, value string) {
log.Printf("sending %q = %q", name, value)
cc.henc.WriteField(hpack.HeaderField{Name: name, Value: value})
}
......@@ -442,21 +441,21 @@ func (cc *clientConn) readLoop() {
cc.readerErr = err
return
}
log.Printf("Transport received %v: %#v", f.Header(), f)
cc.vlogf("Transport received %v: %#v", f.Header(), f)
streamID := f.Header().StreamID
_, isContinue := f.(*ContinuationFrame)
if isContinue {
if streamID != continueStreamID {
log.Printf("Protocol violation: got CONTINUATION with id %d; want %d", streamID, continueStreamID)
cc.logf("Protocol violation: got CONTINUATION with id %d; want %d", streamID, continueStreamID)
cc.readerErr = ConnectionError(ErrCodeProtocol)
return
}
} else if continueStreamID != 0 {
// Continue frames need to be adjacent in the stream
// and we were in the middle of headers.
log.Printf("Protocol violation: got %T for stream %d, want CONTINUATION for %d", f, streamID, continueStreamID)
cc.logf("Protocol violation: got %T for stream %d, want CONTINUATION for %d", f, streamID, continueStreamID)
cc.readerErr = ConnectionError(ErrCodeProtocol)
return
}
......@@ -473,7 +472,7 @@ func (cc *clientConn) readLoop() {
cs := cc.streamByID(streamID, streamEnded)
if cs == nil {
log.Printf("Received frame for untracked stream ID %d", streamID)
cc.logf("Received frame for untracked stream ID %d", streamID)
continue
}
......@@ -489,17 +488,19 @@ func (cc *clientConn) readLoop() {
case *ContinuationFrame:
cc.hdec.Write(f.HeaderBlockFragment())
case *DataFrame:
log.Printf("DATA: %q", f.Data())
if VerboseLogs {
cc.logf("DATA: %q", f.Data())
}
cs.pw.Write(f.Data())
case *GoAwayFrame:
cc.t.removeClientConn(cc)
if f.ErrCode != 0 {
// TODO: deal with GOAWAY more. particularly the error code
log.Printf("transport got GOAWAY with error code = %v", f.ErrCode)
cc.vlogf("transport got GOAWAY with error code = %v", f.ErrCode)
}
cc.setGoAway(f)
default:
log.Printf("Transport: unhandled response frame type %T", f)
cc.logf("Transport: unhandled response frame type %T", f)
}
headersEnded := false
if he, ok := f.(headersEnder); ok {
......@@ -533,7 +534,9 @@ func (cc *clientConn) readLoop() {
func (cc *clientConn) onNewHeaderField(f hpack.HeaderField) {
// TODO: verifiy pseudo headers come before non-pseudo headers
// TODO: verifiy the status is set
log.Printf("Header field: %+v", f)
if VerboseLogs {
cc.logf("Header field: %+v", f)
}
if f.Name == ":status" {
code, err := strconv.Atoi(f.Value)
if err != nil {
......@@ -550,3 +553,21 @@ func (cc *clientConn) onNewHeaderField(f hpack.HeaderField) {
}
cc.nextRes.Header.Add(http.CanonicalHeaderKey(f.Name), f.Value)
}
func (cc *clientConn) logf(format string, args ...interface{}) {
cc.t.logf(format, args...)
}
func (cc *clientConn) vlogf(format string, args ...interface{}) {
cc.t.vlogf(format, args...)
}
func (t *Transport) vlogf(format string, args ...interface{}) {
if VerboseLogs {
t.logf(format, args...)
}
}
func (t *Transport) logf(format string, args ...interface{}) {
log.Printf(format, args...)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment