@@ -36,6 +36,7 @@ import (
36
36
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
37
37
38
38
"github.com/mxk/go-flowrate/flowrate"
39
+
39
40
"k8s.io/klog/v2"
40
41
)
41
42
@@ -336,6 +337,7 @@ func (h *UpgradeAwareHandler) tryUpgrade(w http.ResponseWriter, req *http.Reques
336
337
clone .Host = h .Location .Host
337
338
}
338
339
clone .URL = & location
340
+ klog .V (6 ).Infof ("UpgradeAwareProxy: dialing for SPDY upgrade with headers: %v" , clone .Header )
339
341
backendConn , err = h .DialForUpgrade (clone )
340
342
if err != nil {
341
343
klog .V (6 ).Infof ("Proxy connection error: %v" , err )
@@ -370,13 +372,13 @@ func (h *UpgradeAwareHandler) tryUpgrade(w http.ResponseWriter, req *http.Reques
370
372
// hijacking should be the last step in the upgrade.
371
373
requestHijacker , ok := w .(http.Hijacker )
372
374
if ! ok {
373
- klog .V ( 6 ). Infof ("Unable to hijack response writer: %T" , w )
375
+ klog .Errorf ("Unable to hijack response writer: %T" , w )
374
376
h .Responder .Error (w , req , fmt .Errorf ("request connection cannot be hijacked: %T" , w ))
375
377
return true
376
378
}
377
379
requestHijackedConn , _ , err := requestHijacker .Hijack ()
378
380
if err != nil {
379
- klog .V ( 6 ). Infof ("Unable to hijack response: %v" , err )
381
+ klog .Errorf ("Unable to hijack response: %v" , err )
380
382
h .Responder .Error (w , req , fmt .Errorf ("error hijacking connection: %v" , err ))
381
383
return true
382
384
}
@@ -420,7 +422,7 @@ func (h *UpgradeAwareHandler) tryUpgrade(w http.ResponseWriter, req *http.Reques
420
422
} else {
421
423
writer = backendConn
422
424
}
423
- _ , err := io .Copy (writer , requestHijackedConn )
425
+ _ , err := io .Copy (writer , & loggingReader { name : "client->backend" , delegate : requestHijackedConn } )
424
426
if err != nil && ! strings .Contains (err .Error (), "use of closed network connection" ) {
425
427
klog .Errorf ("Error proxying data from client to backend: %v" , err )
426
428
}
@@ -434,7 +436,7 @@ func (h *UpgradeAwareHandler) tryUpgrade(w http.ResponseWriter, req *http.Reques
434
436
} else {
435
437
reader = backendConn
436
438
}
437
- _ , err := io .Copy (requestHijackedConn , reader )
439
+ _ , err := io .Copy (requestHijackedConn , & loggingReader { name : "backend->client" , delegate : reader } )
438
440
if err != nil && ! strings .Contains (err .Error (), "use of closed network connection" ) {
439
441
klog .Errorf ("Error proxying data from backend to client: %v" , err )
440
442
}
@@ -452,6 +454,18 @@ func (h *UpgradeAwareHandler) tryUpgrade(w http.ResponseWriter, req *http.Reques
452
454
return true
453
455
}
454
456
457
+ // loggingReader logs the bytes read from the "delegate" with a "name" prefix.
458
+ type loggingReader struct {
459
+ name string
460
+ delegate io.Reader
461
+ }
462
+
463
+ func (l * loggingReader ) Read (p []byte ) (int , error ) {
464
+ n , err := l .delegate .Read (p )
465
+ klog .V (8 ).Infof ("%s: %d bytes, err=%v, bytes=% X" , l .name , n , err , p [:n ])
466
+ return n , err
467
+ }
468
+
455
469
// FIXME: Taken from net/http/httputil/reverseproxy.go as singleJoiningSlash is not exported to be re-used.
456
470
// See-also: https://github.com/golang/go/issues/44290
457
471
func singleJoiningSlash (a , b string ) string {
0 commit comments