summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-11-05 16:28:33 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2019-11-05 16:28:33 -0700
commit6e95477224d5fe0856c4fba0f71afe1d7289ed74 (patch)
tree42ac3e804fd38ad7e1acab753c5963709f7ffb30
parent97d918df3e89a3cc4dd5e5c06967bb85870c5ce3 (diff)
http: Eliminate allocation in cloneURL; add RemoteAddr to origRequest
-rw-r--r--modules/caddyhttp/server.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go
index 38d6edd..57d1a3b 100644
--- a/modules/caddyhttp/server.go
+++ b/modules/caddyhttp/server.go
@@ -116,7 +116,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log = logger.Error
}
- log("received request",
+ log("handled request",
zap.String("common_log", repl.ReplaceAll(CommonLogFormat, "-")),
zap.Duration("latency", latency),
zap.Int("size", wrec.Size()),
@@ -392,14 +392,15 @@ func errLogValues(err error) (status int, msg string, fields []zapcore.Field) {
// originalRequest returns a partial, shallow copy of
// req, including: req.Method, deep copy of req.URL
// (into the urlCopy parameter, which should be on the
-// stack), and req.RequestURI. Notably, headers are not
-// copied. This function is designed to be very fast
-// and efficient, and useful primarly for read-only
-// logging purposes.
+// stack), req.RequestURI, and req.RemoteAddr. Notably,
+// headers are not copied. This function is designed to
+// be very fast and efficient, and useful primarly for
+// read-only/logging purposes.
func originalRequest(req *http.Request, urlCopy *url.URL) http.Request {
- urlCopy = cloneURL(req.URL)
+ cloneURL(req.URL, urlCopy)
return http.Request{
Method: req.Method,
+ RemoteAddr: req.RemoteAddr,
RequestURI: req.RequestURI,
URL: urlCopy,
}
@@ -407,14 +408,13 @@ func originalRequest(req *http.Request, urlCopy *url.URL) http.Request {
// cloneURL makes a copy of r.URL and returns a
// new value that doesn't reference the original.
-func cloneURL(u *url.URL) *url.URL {
- urlCopy := *u
- if u.User != nil {
+func cloneURL(from, to *url.URL) {
+ *to = *from
+ if from.User != nil {
userInfo := new(url.Userinfo)
- *userInfo = *u.User
- urlCopy.User = userInfo
+ *userInfo = *from.User
+ to.User = userInfo
}
- return &urlCopy
}
const (