"io/ioutil"
"log"
"net/http"
+ "net/url"
"os"
"path"
"strconv"
MainHandler Handler
)
+func PathWithQuery(u *url.URL) string {
+ if u.RawQuery == "" {
+ return u.EscapedPath()
+ }
+ return u.EscapedPath() + "?" + u.RawQuery
+}
+
type Handler struct{}
func (h Handler) Handle(
) {
notFound := func() {
fmt.Printf("%s %s \"%s %+q %s\" %d \"%s\"\n",
- r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto,
+ r.RemoteAddr, host, r.Method, PathWithQuery(r.URL), r.Proto,
http.StatusNotFound,
r.Header.Get("User-Agent"),
)
}
printErr := func(code int, err error) {
fmt.Printf("%s %s \"%s %+q %s\" %d \"%s\" %s\"%s\"\n",
- r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto,
+ r.RemoteAddr, host, r.Method, PathWithQuery(r.URL), r.Proto,
code, err.Error(),
username, r.Header.Get("User-Agent"),
)
wc := &CountResponseWriter{ResponseWriter: w}
dav.ServeHTTP(wc, r)
fmt.Printf("%s %s \"WebDAV %+q\" %d %d %s\"%s\"\n",
- r.RemoteAddr, host, r.URL.Path,
+ r.RemoteAddr, host, PathWithQuery(r.URL),
wc.Status, wc.Size,
username, r.Header.Get("User-Agent"),
)
if !(r.Method == "" || r.Method == http.MethodGet) {
fmt.Printf("%s %s \"%s %+q %s\" %d %s\"%s\"\n",
- r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto,
+ r.RemoteAddr, host, r.Method, PathWithQuery(r.URL), r.Proto,
http.StatusMethodNotAllowed,
username, r.Header.Get("User-Agent"),
)
w.WriteHeader(wr.status)
w.Write(bufCompressed.Bytes())
fmt.Printf("%s %s \"%s %+q %s\" %d %d %s\"%s\"\n",
- r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto,
+ r.RemoteAddr, host, r.Method, PathWithQuery(r.URL), r.Proto,
wr.status, size,
username, r.Header.Get("User-Agent"),
)
}
wr := wc.(*CountResponseWriter)
fmt.Printf("%s %s \"%s %+q %s\" %d %d %s\"%s\"\n",
- r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto,
+ r.RemoteAddr, host, r.Method, PathWithQuery(r.URL), r.Proto,
wr.Status, wr.Size,
username, r.Header.Get("User-Agent"),
)
)
func RunCGIAndLog(host string, w http.ResponseWriter, r *http.Request, h *cgi.Handler) {
- wc := &godlighty.CountResponseWriter{ResponseWriter: w}
if r.TLS != nil && len(r.TLS.PeerCertificates) > 0 {
h.Env = append(h.Env, "TLSREMOTEDN="+r.TLS.PeerCertificates[0].Subject.String())
}
+ wc := &godlighty.CountResponseWriter{ResponseWriter: w}
h.ServeHTTP(wc, r)
fmt.Printf("%s %s \"%s %+q %s\" %d %d \"%s\"\n",
- r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto,
+ r.RemoteAddr, host, r.Method, godlighty.PathWithQuery(r.URL), r.Proto,
wc.Status, wc.Size,
r.Header.Get("User-Agent"),
)
resp, err := http.DefaultClient.Do(r)
if err != nil {
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.RemoteAddr, host, r.Method, godlighty.PathWithQuery(r.URL),
+ r.Proto, http.StatusBadGateway, err.Error(),
r.Header.Get("User-Agent"),
)
http.Error(w, err.Error(), http.StatusBadGateway)
size, _ := io.Copy(w, resp.Body)
resp.Body.Close()
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.RemoteAddr, host, r.Method, godlighty.PathWithQuery(r.URL),
+ r.Proto, resp.StatusCode, size,
r.Header.Get("User-Agent"),
)
return true
import (
"fmt"
"net/http"
+
+ "go.stargrave.org/godlighty"
)
func Redirect(
) {
http.Redirect(w, r, to, status)
fmt.Printf("%s %s \"%s %+q %s\" %d \"%s\"\n",
- r.RemoteAddr, host, r.Method, r.URL.Path, r.Proto,
+ r.RemoteAddr, host, r.Method, godlighty.PathWithQuery(r.URL), r.Proto,
status, r.Header.Get("User-Agent"),
)
}