Skip to content

Instantly share code, notes, and snippets.

@bertt
Created October 9, 2017 12:19
Show Gist options
  • Save bertt/a555bee939166c6967d7b48cb2606936 to your computer and use it in GitHub Desktop.
Save bertt/a555bee939166c6967d7b48cb2606936 to your computer and use it in GitHub Desktop.
Print request
package main
import (
"fmt"
"net/http"
"sort"
"strings"
)
func handler(w http.ResponseWriter, r *http.Request) {
var keys []string
for k := range r.Header {
keys = append(keys, k)
}
sort.Strings(keys)
subdomain := strings.Split(r.Host, ".")[0]
fmt.Fprintln(w, "<b>Subdomain: "+subdomain+"</b></br")
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:])
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment