forked from daime/http-dump
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
43 lines (34 loc) · 817 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
"os"
)
var port = "8080"
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
d, err := httputil.DumpRequest(r, true)
if err != nil {
msg := fmt.Sprintf("couldn't dump request: %s", err)
log.Printf(msg)
http.Error(w, msg, http.StatusInternalServerError)
return
}
b := string(d)
log.Printf("request received:\n%s\n\n", b)
if _, err := fmt.Fprintf(w, b); err != nil {
msg := fmt.Sprintf("couldn't write response: %s", err)
log.Printf(msg)
http.Error(w, msg, http.StatusInternalServerError)
return
}
})
if p := os.Getenv("PORT"); p != "" {
port = p
}
addr := ":" + port
log.Printf("http-dump is listening at %s\n", addr)
log.Fatal(http.ListenAndServe(addr, nil))
}