forked from daime/http-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (39 loc) · 963 Bytes
/
main.go
File metadata and controls
48 lines (39 loc) · 963 Bytes
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
44
45
46
47
48
package main
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
"os"
"strings"
)
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
}
lg := fmt.Sprintf("%q", d)
lg = strings.TrimPrefix(lg, "\"")
lg = strings.TrimSuffix(lg, "\"")
fmt.Println(lg)
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
if _, err := fmt.Fprintf(w, ""); 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))
}