From fc53179739faac1db1bba67fc0f6d4df65940fac Mon Sep 17 00:00:00 2001 From: SAILESH4406 Date: Sun, 15 Feb 2026 22:42:07 +0530 Subject: [PATCH] Fix Traefik POST / to echo request body (#54) --- src/Servers/TraefikServer/echo/main.go | 27 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Servers/TraefikServer/echo/main.go b/src/Servers/TraefikServer/echo/main.go index 592f149..9a930e2 100644 --- a/src/Servers/TraefikServer/echo/main.go +++ b/src/Servers/TraefikServer/echo/main.go @@ -1,21 +1,28 @@ package main import ( - "fmt" + "io" "net/http" - "strings" ) func main() { - http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - var sb strings.Builder - for name, values := range r.Header { - for _, v := range values { - sb.WriteString(fmt.Sprintf("%s: %s\n", name, v)) - } + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost { + http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) + return + } + + body, err := io.ReadAll(r.Body) + if err != nil { + http.Error(w, "Failed to read body", http.StatusBadRequest) + return } - fmt.Fprint(w, sb.String()) + defer r.Body.Close() + + w.Header().Set("Content-Type", "text/plain") + w.WriteHeader(http.StatusOK) + w.Write(body) }) + http.ListenAndServe(":9090", nil) }