Skip to content

Commit

Permalink
v0.0.1
Browse files Browse the repository at this point in the history
 - Debug the given input request
  • Loading branch information
alessiosavi committed Apr 16, 2020
0 parents commit 33d746a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/alessiosavi/GoHttpDebugRequest

go 1.14

require github.com/gorilla/mux v1.7.4
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
36 changes: 36 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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("/post", DumpRequest).Methods("POST")
log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", *host, *port), router))
}

0 comments on commit 33d746a

Please sign in to comment.