mirror of
https://github.com/kevwan/tproxy.git
synced 2026-05-23 07:40:35 +00:00
Fix #104: Display correct protocol name in logs
- Add protocol field to http2Interop struct to track actual protocol - Use stored protocol name instead of hardcoded 'grpc' in output - Now http2 mode shows 'http2:' prefix and grpc mode shows 'grpc:' prefix - Move grpcHeaderLen constant to grpc.go to avoid duplication
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
)
|
||||
|
||||
const grpcHeaderLen = 5
|
||||
|
||||
type grpcExplainer struct{}
|
||||
|
||||
func (g *grpcExplainer) explain(b []byte) string {
|
||||
|
||||
+6
-2
@@ -18,7 +18,6 @@ const (
|
||||
http2HeaderLen = 9
|
||||
http2Preface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
|
||||
http2SettingsPayloadLen = 6
|
||||
grpcHeaderLen = 5
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -28,6 +27,7 @@ type (
|
||||
|
||||
http2Interop struct {
|
||||
explainer dataExplainer
|
||||
protocol string
|
||||
}
|
||||
)
|
||||
|
||||
@@ -44,8 +44,12 @@ func (i *http2Interop) Dump(r io.Reader, source string, id int, quiet bool) {
|
||||
var index int
|
||||
for index < n {
|
||||
frameInfo, moreInfo, offset := i.explain(data[index:n])
|
||||
protocol := i.protocol
|
||||
if len(protocol) == 0 {
|
||||
protocol = http2Protocol
|
||||
}
|
||||
buf.WriteString(fmt.Sprintf("%s%s%s\n",
|
||||
color.HiBlueString("%s:(", grpcProtocol),
|
||||
color.HiBlueString("%s:(", protocol),
|
||||
color.HiYellowString(frameInfo),
|
||||
color.HiBlueString(")")))
|
||||
end := index + offset
|
||||
|
||||
+4
-1
@@ -35,9 +35,12 @@ func CreateInterop(protocol string) Interop {
|
||||
case grpcProtocol:
|
||||
return &http2Interop{
|
||||
explainer: new(grpcExplainer),
|
||||
protocol: grpcProtocol,
|
||||
}
|
||||
case http2Protocol:
|
||||
return new(http2Interop)
|
||||
return &http2Interop{
|
||||
protocol: http2Protocol,
|
||||
}
|
||||
case redisProtocol:
|
||||
return new(redisInterop)
|
||||
case mongoProtocol:
|
||||
|
||||
Reference in New Issue
Block a user