package main import ( "fmt" "io/ioutil" "net/http" "os" "time" "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) fmt.Fprintln(accessf, time.Now(), host, proto, addr, url, agent) // return fmt.Fprintln(clientf) fmt.Fprintln(clientf, time.Now()) // Basic request information 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) // Headers fmt.Fprintln(clientf, "Headers:") for name, values := range r.Header { for _, value := range values { fmt.Fprintln(clientf, "Headers:", name, value) } } // Query parameters fmt.Fprintln(clientf, "Query Parameters:") for param, values := range r.URL.Query() { for _, value := range values { fmt.Fprintln(clientf, "Query:", param, value) } } // User-Agent fmt.Fprintln(clientf, "User-Agent:", r.UserAgent()) // Content Length fmt.Fprintln(clientf, "Content Length:", r.ContentLength) // Cookies fmt.Fprintln(clientf, "Cookies:") for _, cookie := range r.Cookies() { fmt.Fprintln(clientf, cookie.Name, cookie.Value) } // Request Body (if applicable) if r.Body != nil { body, err := ioutil.ReadAll(r.Body) if err == nil { fmt.Fprintln(clientf, "Body:", string(body)) } } } func registerClient(f *os.File, r *http.Request) bool { var host, url, proto, addr, agent string var giturl, gopath string host = r.Host url = r.URL.String() proto = r.Proto addr = r.RemoteAddr agent = r.UserAgent() log.Warn(host, proto, addr, url, agent) fmt.Fprintln(f, time.Now(), host, proto, addr, url, agent) // return fmt.Fprintln(f) fmt.Fprintln(f, time.Now()) // Basic request information fmt.Fprintln(f, "Method:", r.Method) fmt.Fprintln(f, "URL:", r.URL) fmt.Fprintln(f, "Protocol:", r.Proto) fmt.Fprintln(f, "Host:", r.Host) fmt.Fprintln(f, "Remote Address:", r.RemoteAddr) // Headers fmt.Fprintln(f, "Headers:") for name, values := range r.Header { for _, value := range values { fmt.Fprintln(f, "Headers:", name, value) if name == "Giturl" { giturl = value } if name == "Gopath" { gopath = value } // Giturl https://git.wit.org/gui/go-gui-toolkits.git // Headers: Gopath } } // Query parameters fmt.Fprintln(f, "Query Parameters:") for param, values := range r.URL.Query() { for _, value := range values { fmt.Fprintln(f, "Query:", param, value) } } // User-Agent fmt.Fprintln(f, "User-Agent:", r.UserAgent()) // Content Length fmt.Fprintln(f, "Content Length:", r.ContentLength) // Cookies fmt.Fprintln(f, "Cookies:") for _, cookie := range r.Cookies() { fmt.Fprintln(f, cookie.Name, cookie.Value) } // Request Body (if applicable) if r.Body != nil { body, err := ioutil.ReadAll(r.Body) if err == nil { fmt.Fprintln(f, "Body:", string(body)) } } fmt.Fprintln(f, "gopath =", gopath, "giturl =", giturl) if gopath == "" { return false } if giturl == "" { return false } fmt.Fprintln(f, "Sent back OK") return true }