Skip to content

Instantly share code, notes, and snippets.

@empijei
Created April 17, 2017 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save empijei/c1117a074372b905832cc1f804309343 to your computer and use it in GitHub Desktop.
Save empijei/c1117a074372b905832cc1f804309343 to your computer and use it in GitHub Desktop.
dump http requests
package main
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
"os"
)
type cHandler struct{}
var customhandler = &cHandler{}
func (c *cHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
buf, _ := httputil.DumpRequest(r, true)
fmt.Println(string(buf))
http.DefaultServeMux.ServeHTTP(w, r)
}
func main() {
port := os.Getenv("PORT")
if port == "" {
log.Fatal("$PORT must be set")
}
http.Handle("/website/", http.StripPrefix("/website/", http.FileServer(http.Dir("website"))))
_ = http.ListenAndServe(":"+port, customhandler)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment