Skip to content

Commit 3d3085d

Browse files
authored
Merge pull request #79 from SAILESH4406/fix-traefik-post-echo
Fix Traefik POST / to echo request body (#54)
2 parents 484537d + fc53179 commit 3d3085d

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

  • src/Servers/TraefikServer/echo
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
package main
22

33
import (
4-
"fmt"
4+
"io"
55
"net/http"
6-
"strings"
76
)
87

98
func main() {
10-
http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
11-
w.Header().Set("Content-Type", "text/plain")
12-
var sb strings.Builder
13-
for name, values := range r.Header {
14-
for _, v := range values {
15-
sb.WriteString(fmt.Sprintf("%s: %s\n", name, v))
16-
}
9+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
10+
if r.Method != http.MethodPost {
11+
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
12+
return
13+
}
14+
15+
body, err := io.ReadAll(r.Body)
16+
if err != nil {
17+
http.Error(w, "Failed to read body", http.StatusBadRequest)
18+
return
1719
}
18-
fmt.Fprint(w, sb.String())
20+
defer r.Body.Close()
21+
22+
w.Header().Set("Content-Type", "text/plain")
23+
w.WriteHeader(http.StatusOK)
24+
w.Write(body)
1925
})
26+
2027
http.ListenAndServe(":9090", nil)
2128
}

0 commit comments

Comments
 (0)