Created
October 9, 2017 12:19
-
-
Save bertt/a555bee939166c6967d7b48cb2606936 to your computer and use it in GitHub Desktop.
Print request
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" | |
"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