2024-01-12 04:14:09 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-14 11:39:22 -06:00
|
|
|
"fmt"
|
|
|
|
"time"
|
2024-01-12 04:14:09 -06:00
|
|
|
"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)
|
|
|
|
|
2024-01-14 11:39:22 -06:00
|
|
|
fmt.Fprintln(accessf, time.Now(), host, proto, addr, url, agent)
|
|
|
|
// return
|
|
|
|
|
|
|
|
fmt.Fprintln(clientf)
|
|
|
|
fmt.Fprintln(clientf, time.Now())
|
2024-01-12 04:14:09 -06:00
|
|
|
// Basic request information
|
2024-01-14 11:39:22 -06:00
|
|
|
fmt.Fprintln(clientf, "Method:", r.Method)
|
|
|
|
fmt.Fprintln(clientf, "URL:", r.URL)
|
|
|
|
fmt.Fprintln(clientf, "Protocol:", r.Proto)
|
|
|
|
fmt.Fprintln(clientf, "Host:", r.Host)
|
|
|
|
fmt.Fprintln(clientf, "Remote Address:", r.RemoteAddr)
|
2024-01-12 04:14:09 -06:00
|
|
|
|
2024-01-12 16:04:08 -06:00
|
|
|
|
2024-01-12 04:14:09 -06:00
|
|
|
// Headers
|
2024-01-14 11:39:22 -06:00
|
|
|
fmt.Fprintln(clientf,"Headers:")
|
2024-01-12 04:14:09 -06:00
|
|
|
for name, values := range r.Header {
|
|
|
|
for _, value := range values {
|
2024-01-14 11:39:22 -06:00
|
|
|
fmt.Fprintln(clientf, "Headers:", name, value)
|
2024-01-12 04:14:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Query parameters
|
2024-01-14 11:39:22 -06:00
|
|
|
fmt.Fprintln(clientf, "Query Parameters:")
|
2024-01-12 04:14:09 -06:00
|
|
|
for param, values := range r.URL.Query() {
|
|
|
|
for _, value := range values {
|
2024-01-14 11:39:22 -06:00
|
|
|
fmt.Fprintln(clientf, "Query:", param, value)
|
2024-01-12 04:14:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// User-Agent
|
2024-01-14 11:39:22 -06:00
|
|
|
fmt.Fprintln(clientf, "User-Agent:", r.UserAgent())
|
2024-01-12 04:14:09 -06:00
|
|
|
|
|
|
|
// Content Length
|
2024-01-14 11:39:22 -06:00
|
|
|
fmt.Fprintln(clientf, "Content Length:", r.ContentLength)
|
2024-01-12 04:14:09 -06:00
|
|
|
|
|
|
|
// Cookies
|
2024-01-14 11:39:22 -06:00
|
|
|
fmt.Fprintln(clientf,"Cookies:")
|
2024-01-12 04:14:09 -06:00
|
|
|
for _, cookie := range r.Cookies() {
|
2024-01-14 11:39:22 -06:00
|
|
|
fmt.Fprintln(clientf, cookie.Name, cookie.Value)
|
2024-01-12 04:14:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Request Body (if applicable)
|
|
|
|
if r.Body != nil {
|
|
|
|
body, err := ioutil.ReadAll(r.Body)
|
|
|
|
if err == nil {
|
2024-01-14 11:39:22 -06:00
|
|
|
fmt.Fprintln(clientf, "Body:", string(body))
|
2024-01-12 04:14:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|