forked from chennqqi/http-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (33 loc) · 808 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
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
}
log.Printf("Request received:\n%s\n\n", d)
if _, err := fmt.Fprintf(w, string("")); 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))
}