From 35442ca9fbb6059bc46295b2b93e55d90f5b8994 Mon Sep 17 00:00:00 2001
From: Nedyalko Andreev <n@andreev.sh>
Date: Thu, 22 Mar 2018 11:39:39 +0200
Subject: [PATCH] Fix logging of HEAD requests

---
 httpbin/middleware.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/httpbin/middleware.go b/httpbin/middleware.go
index 30acaf8..e53bcab 100644
--- a/httpbin/middleware.go
+++ b/httpbin/middleware.go
@@ -109,10 +109,11 @@ func (mw *metaResponseWriter) Size() int {
 
 func logger(h http.Handler) http.Handler {
 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		reqMethod, reqURI := r.Method, r.URL.RequestURI()
 		mw := &metaResponseWriter{w: w}
 		t := time.Now()
 		h.ServeHTTP(mw, r)
 		duration := time.Now().Sub(t)
-		log.Printf("status=%d method=%s uri=%q size=%d duration=%s", mw.Status(), r.Method, r.URL.RequestURI(), mw.Size(), duration)
+		log.Printf("status=%d method=%s uri=%q size=%d duration=%s", mw.Status(), reqMethod, reqURI, mw.Size(), duration)
 	})
 }
-- 
GitLab