peek at reply

This commit is contained in:
Bel LaPointe
2026-02-04 09:02:41 -07:00
parent 9e0754d92f
commit eedb785634

View File

@@ -47,8 +47,6 @@ func adapt(ctx context.Context, config Config, conn net.Conn) error {
}
log.Printf("hashkey %q", hashKey)
if err := config.WithConn(hashKey, func(forwardConn net.Conn) error {
//log.Printf("forwarding %q", raw)
written := 0
for written < len(raw) {
more, err := forwardConn.Write(raw[written:])
@@ -58,11 +56,16 @@ func adapt(ctx context.Context, config Config, conn net.Conn) error {
written += more
}
replyer := bufio.NewReader(forwardConn)
//log.Printf("reading reply to %q", raw)
_, err = readMessageTo(conn, replyer)
//log.Printf("read reply %q", raw)
return err
peekW := bytes.NewBuffer(nil)
peek := io.TeeReader(forwardConn, peekW)
defer func() {
replied := peekW.Bytes()
if len(replied) > 100 {
replied = []byte(fmt.Sprintf("%s...%s", replied[:50], replied[len(replied)-50:]))
}
log.Printf("replied %q", replied)
}()
return readMessageTo(conn, bufio.NewReader(peek))
}); err != nil {
return true, err
}
@@ -133,14 +136,14 @@ func _readMessageTo(w io.Writer, reader *bufio.Reader) error {
}
fmt.Fprintf(w, "%s", nextLine)
return err
case '*', '%': // *=array %=map, like *-1 for nil, like *4 for [1,2,3,4]
case '*', '~', '%': // *=array %=map, like *-1 for nil, like *4 for [1,2,3,4]
n, err := strconv.Atoi(string(firstLine[1:]))
if err != nil {
return fmt.Errorf("arr not a num: %q: %w", firstLine, err)
} else if n == -1 {
return nil
}
if firstLine[0] == '%' {
if isMap := firstLine[0] == '%'; isMap {
n *= 2
}
for i := 0; i < n; i++ {