Skip to content

Instantly share code, notes, and snippets.

@crgimenes
Created March 3, 2024 02:09
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 crgimenes/54c313fd6bddd3dae4bd7969410ff61d to your computer and use it in GitHub Desktop.
Save crgimenes/54c313fd6bddd3dae4bd7969410ff61d to your computer and use it in GitHub Desktop.
Simple http dump server
package main
import (
"flag"
"fmt"
"log"
"net/http"
"net/http/httputil"
)
func handler(w http.ResponseWriter, r *http.Request) {
b, err := httputil.DumpRequest(r, true)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// titulo verde
ret := fmt.Sprintf("\033[32mDumped request:\033[0m\n%s\n", string(b))
fmt.Printf(ret)
// linha magenta
fmt.Printf("\033[35m-----------------------\033[0m\n")
w.Write([]byte(ret))
}
func main() {
port := 8080
flag.IntVar(&port, "port", port, "TCP port, default 8080")
flag.Parse()
http.HandleFunc("/", handler)
fmt.Printf("listening on %v\n", port)
err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment