From d02e35bb22060f47e524107176c28a8773be5688 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 19 Apr 2026 14:04:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Modify=20logging=20and=20comment?= =?UTF-8?q?=20handling=20in=20proxy=20and=20stream=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index c50abc0..5aae16a 100644 --- a/main.go +++ b/main.go @@ -76,7 +76,7 @@ func handleProxy(cfg Config) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { requestId := uuid.New().String() - log.Println(requestId, "Handle proxy:", r.URL) + log.Println(requestId, "Handle proxy:", r.Method, r.URL) if r.URL.Path == "/health" { w.WriteHeader(http.StatusOK) return @@ -195,6 +195,9 @@ func handleStream(requestId string, w io.Writer, body io.Reader) { reader := bufio.NewReader(body) for { + // log.Println("Sleep:", 4) + // time.Sleep(time.Duration(4) * time.Second) + line, err := reader.ReadString('\n') if err != nil { if err != io.EOF { @@ -206,7 +209,6 @@ func handleStream(requestId string, w io.Writer, body io.Reader) { break } - // Write the line as-is without trimming _, writeErr := rw.Write([]byte(line)) if writeErr != nil { log.Println(requestId, "Write error:", writeErr) @@ -215,6 +217,7 @@ func handleStream(requestId string, w io.Writer, body io.Reader) { if len(line) == 1 && line[len(line)-1] == 10 { // SKIP empty line + continue } else { log.Println(requestId, "Process chunk:", fmt.Sprintf("%d bytes", len(line)), strings.TrimSpace(line)) }