From d25bee6e2b2d1830ad225ba043a4480178753f9c Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 8 Oct 2021 20:26:21 +0300 Subject: [PATCH] Do not print raw URL path --- handler.go | 12 ++++++------ rc/cgi.go | 2 +- rc/example.cfg/proxied-host.go | 4 ++-- rc/redirect.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/handler.go b/handler.go index df16c38..4593a2f 100644 --- a/handler.go +++ b/handler.go @@ -69,7 +69,7 @@ func (h Handler) Handle( host string, cfg *HostCfg, ) { notFound := func() { - fmt.Printf("%s %s \"%s %s %s\" %d \"%s\"\n", + fmt.Printf("%s %s \"%s %+q %s\" %d \"%s\"\n", r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto, http.StatusNotFound, r.Header.Get("User-Agent"), @@ -90,7 +90,7 @@ func (h Handler) Handle( username = "user:" + username + " " } printErr := func(code int, err error) { - fmt.Printf("%s %s \"%s %s %s\" %d \"%s\" %s\"%s\"\n", + fmt.Printf("%s %s \"%s %+q %s\" %d \"%s\" %s\"%s\"\n", r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto, code, err.Error(), username, r.Header.Get("User-Agent"), @@ -139,7 +139,7 @@ func (h Handler) Handle( } wc := &CountResponseWriter{ResponseWriter: w} dav.ServeHTTP(wc, r) - fmt.Printf("%s %s \"WebDAV %s\" %d %d %s\"%s\"\n", + fmt.Printf("%s %s \"WebDAV %+q\" %d %d %s\"%s\"\n", r.RemoteAddr, host, r.URL.Path, wc.Status, wc.Size, username, r.Header.Get("User-Agent"), @@ -148,7 +148,7 @@ func (h Handler) Handle( } if !(r.Method == "" || r.Method == http.MethodGet) { - fmt.Printf("%s %s \"%s %s %s\" %d %s\"%s\"\n", + fmt.Printf("%s %s \"%s %+q %s\" %d %s\"%s\"\n", r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto, http.StatusMethodNotAllowed, username, r.Header.Get("User-Agent"), @@ -285,7 +285,7 @@ IndexLookup: wr := wc.(*gzipResponseWriter) w.WriteHeader(wr.status) w.Write(bufCompressed.Bytes()) - fmt.Printf("%s %s \"%s %s %s\" %d %d %s\"%s\"\n", + fmt.Printf("%s %s \"%s %+q %s\" %d %d %s\"%s\"\n", r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto, wr.status, size, username, r.Header.Get("User-Agent"), @@ -293,7 +293,7 @@ IndexLookup: return } wr := wc.(*CountResponseWriter) - fmt.Printf("%s %s \"%s %s %s\" %d %d %s\"%s\"\n", + fmt.Printf("%s %s \"%s %+q %s\" %d %d %s\"%s\"\n", r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto, wr.Status, wr.Size, username, r.Header.Get("User-Agent"), diff --git a/rc/cgi.go b/rc/cgi.go index 8dab80f..e17935a 100644 --- a/rc/cgi.go +++ b/rc/cgi.go @@ -31,7 +31,7 @@ func RunCGIAndLog(host string, w http.ResponseWriter, r *http.Request, h *cgi.Ha h.Env = append(h.Env, "TLSREMOTEDN="+r.TLS.PeerCertificates[0].Subject.String()) } h.ServeHTTP(wc, r) - fmt.Printf("%s %s \"%s %s %s\" %d %d \"%s\"\n", + fmt.Printf("%s %s \"%s %+q %s\" %d %d \"%s\"\n", r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto, wc.Status, wc.Size, r.Header.Get("User-Agent"), diff --git a/rc/example.cfg/proxied-host.go b/rc/example.cfg/proxied-host.go index 1ad0db6..5b61c4d 100644 --- a/rc/example.cfg/proxied-host.go +++ b/rc/example.cfg/proxied-host.go @@ -19,7 +19,7 @@ func init() { r.Host = host resp, err := http.DefaultClient.Do(r) if err != nil { - fmt.Printf("%s %s \"%s %s %s\" %d \"%s\" \"%s\"\n", + fmt.Printf("%s %s \"%s %+q %s\" %d \"%s\" \"%s\"\n", r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto, http.StatusBadGateway, err.Error(), r.Header.Get("User-Agent"), @@ -35,7 +35,7 @@ func init() { w.WriteHeader(resp.StatusCode) size, _ := io.Copy(w, resp.Body) resp.Body.Close() - fmt.Printf("%s %s \"%s %s %s\" %d %d \"%s\"\n", + fmt.Printf("%s %s \"%s %+q %s\" %d %d \"%s\"\n", r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto, resp.StatusCode, size, r.Header.Get("User-Agent"), diff --git a/rc/redirect.go b/rc/redirect.go index ecbdbfb..2039a07 100644 --- a/rc/redirect.go +++ b/rc/redirect.go @@ -28,7 +28,7 @@ func Redirect( to string, status int, ) { http.Redirect(w, r, to, status) - fmt.Printf("%s %s \"%s %s %s\" %d \"%s\"\n", + fmt.Printf("%s %s \"%s %+q %s\" %d \"%s\"\n", r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto, status, r.Header.Get("User-Agent"), ) -- 2.44.0