🔧 Modify logging and comment handling in proxy and stream functions
This commit is contained in:
7
main.go
7
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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user