gowebd/dumpClient.go

67 lines
1.2 KiB
Go
Raw Normal View History

package main
import (
// "fmt"
"net/http"
"io/ioutil"
"go.wit.com/log"
)
func dumpClient(r *http.Request) {
var host, url, proto, addr, agent string
host = r.Host
url = r.URL.String()
proto = r.Proto
addr = r.RemoteAddr
agent = r.UserAgent()
log.Warn(host, proto, addr, url, agent)
return
// Basic request information
log.Println("Method:", r.Method)
log.Println("URL:", r.URL)
log.Println("Protocol:", r.Proto)
log.Println("Host:", r.Host)
log.Println("Remote Address:", r.RemoteAddr)
// Headers
log.Println("Headers:")
for name, values := range r.Header {
for _, value := range values {
log.Println("Headers:", name, value)
}
}
// Query parameters
log.Println("Query Parameters:")
for param, values := range r.URL.Query() {
for _, value := range values {
log.Println("Query:", param, value)
}
}
// User-Agent
log.Println("User-Agent:", r.UserAgent())
// Content Length
log.Println("Content Length:", r.ContentLength)
// Cookies
log.Println("Cookies:")
for _, cookie := range r.Cookies() {
log.Println(cookie.Name, cookie.Value)
}
// Request Body (if applicable)
if r.Body != nil {
body, err := ioutil.ReadAll(r.Body)
if err == nil {
log.Println("Body:", string(body))
}
}
}