Created
June 7, 2016 21:46
-
-
Save lsferreira42/12a71b4a12921e2357f62ec0344cd96b 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" | |
"net/http" | |
"sort" | |
"os" | |
) | |
func handler(w http.ResponseWriter, r *http.Request) { | |
var keys []string | |
for k := range r.Header { | |
keys = append(keys, k) | |
} | |
sort.Strings(keys) | |
fmt.Fprintln(w, "<b>Request Headers:</b></br>", r.URL.Path[1:]) | |
for _, k := range keys { | |
fmt.Fprintln(w, k, ":", r.Header[k], "</br>", r.URL.Path[1:]) | |
} | |
fmt.Fprintln(w, "Port: ", os.Args[1]) | |
fmt.Printf("%s %s %s\n", r.RemoteAddr, r.Method, r.URL) | |
} | |
func main() { | |
http.HandleFunc("/", handler) | |
http.ListenAndServe(os.Args[1], nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment