lwzm
1/7/2020 - 2:47 AM

http-print.go

package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
)

func init() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		bs, _ := ioutil.ReadAll(r.Body)
		s := fmt.Sprintf(
			"%s %s %s%s\n%s\n",
			r.RemoteAddr,
			r.Method,
			r.Host,
			r.URL,
			string(bs),
		)
		log.Println(s)
		w.Write([]byte(s))
	})
}

func main() {
	log.Fatal(http.ListenAndServe(":1111", nil))
}