Skip to content

Instantly share code, notes, and snippets.

@lsferreira42
Created June 7, 2016 21:46
Show Gist options
  • Save lsferreira42/12a71b4a12921e2357f62ec0344cd96b to your computer and use it in GitHub Desktop.
Save lsferreira42/12a71b4a12921e2357f62ec0344cd96b to your computer and use it in GitHub Desktop.
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