Skip to content

Instantly share code, notes, and snippets.

@lesnuages
Created September 3, 2019 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lesnuages/794ca9e62939a580a68ae02ae1a842bd to your computer and use it in GitHub Desktop.
Save lesnuages/794ca9e62939a580a68ae02ae1a842bd to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)
func dumpReq(r *http.Request) {
fmt.Println("========================================================")
fmt.Printf("Connection from %v\n", r.RemoteAddr)
fmt.Println("--------------------------------------------------------")
fmt.Printf("%s %s %s\n", r.Method, r.RequestURI, r.Proto)
for name, val := range r.Header {
fmt.Printf("%s:%s\n", name, val)
}
body, _ := ioutil.ReadAll(r.Body)
fmt.Println()
fmt.Println(string(body))
fmt.Println()
}
func defaultHandler(w http.ResponseWriter, r *http.Request) {
dumpReq(r)
}
func main() {
if len(os.Args) != 2 {
println("You must provide a listening port")
return
}
port := os.Args[1]
http.HandleFunc("/", defaultHandler)
if err := http.ListenAndServe(":"+port, nil); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment