Created
September 3, 2019 13:28
-
-
Save lesnuages/794ca9e62939a580a68ae02ae1a842bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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