-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (38 loc) · 1.26 KB
/
main.go
File metadata and controls
44 lines (38 loc) · 1.26 KB
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
package main
import (
"flag"
"fmt"
"log"
"net/http"
"net/http/httputil"
"github.com/gorilla/mux"
)
func DumpRequest(w http.ResponseWriter, req *http.Request) {
requestDump, err := httputil.DumpRequest(req, true)
if err != nil {
fmt.Fprint(w, err.Error())
fmt.Println(err)
} else {
fmt.Fprint(w, string(requestDump))
fmt.Println(string(requestDump))
}
}
func main() {
port := flag.Int("port", 9999, "Bind the server to the given port")
host := flag.String("host", "localhost", "Bind the server to the given host")
flag.Parse()
if *port == 9999 && *host == "localhost" {
flag.Usage()
}
router := mux.NewRouter()
router.HandleFunc("/get", DumpRequest).Methods("GET")
router.HandleFunc("/head", DumpRequest).Methods("HEAD")
router.HandleFunc("/post", DumpRequest).Methods("POST")
router.HandleFunc("/put", DumpRequest).Methods("PUT")
router.HandleFunc("/delete", DumpRequest).Methods("DELETE")
router.HandleFunc("/connect", DumpRequest).Methods("CONNECT")
router.HandleFunc("/options", DumpRequest).Methods("OPTIONS")
router.HandleFunc("/trace", DumpRequest).Methods("TRACE")
router.HandleFunc("/patch", DumpRequest).Methods("PATCH")
log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", *host, *port), router))
}