2024-01-12 04:14:09 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
// "fmt"
|
|
|
|
"net/http"
|
|
|
|
"io/ioutil"
|
2024-01-12 16:04:08 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
2024-01-12 04:14:09 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func dumpClient(r *http.Request) {
|
2024-01-12 16:04:08 -06:00
|
|
|
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
|
|
|
|
|
2024-01-12 04:14:09 -06:00
|
|
|
// 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)
|
|
|
|
|
2024-01-12 16:04:08 -06:00
|
|
|
|
2024-01-12 04:14:09 -06:00
|
|
|
// Headers
|
|
|
|
log.Println("Headers:")
|
|
|
|
for name, values := range r.Header {
|
|
|
|
for _, value := range values {
|
2024-01-12 16:04:08 -06:00
|
|
|
log.Println("Headers:", name, value)
|
2024-01-12 04:14:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Query parameters
|
|
|
|
log.Println("Query Parameters:")
|
|
|
|
for param, values := range r.URL.Query() {
|
|
|
|
for _, value := range values {
|
2024-01-12 16:04:08 -06:00
|
|
|
log.Println("Query:", param, value)
|
2024-01-12 04:14:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|