63786d05e03f584f80d32f56bc77f4a8a87e4d2f

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

fix(web): superfluous write

Diff

 1diff --git a/pkg/web/context.go b/pkg/web/context.go
 2index e8aae8f7ea0286ebc659e30298e68e1f7f14d99b..ccba92776861ac7108851c0ace1845b7a1311936 100644
 3--- a/pkg/web/context.go
 4+++ b/pkg/web/context.go
 5@@ -32,6 +32,7 @@ func NewContextHandler(ctx context.Context) func(http.Handler) http.Handler {
 6 			ctx = db.WithContext(ctx, dbx)
 7 			ctx = store.WithContext(ctx, datastore)
 8 			r = r.WithContext(ctx)
 9+
10 			next.ServeHTTP(w, r)
11 		})
12 	}
13diff --git a/pkg/web/git.go b/pkg/web/git.go
14index 364530f623e42c95d44e9c02c39ccc481ec61d10..c03e56afd591285aeb34146f9d0211dd01b9db73 100644
15--- a/pkg/web/git.go
16+++ b/pkg/web/git.go
17@@ -72,7 +72,7 @@ var (
18 	}, []string{"repo", "file"})
19 )
20 
21-func withParams(h http.Handler) http.Handler {
22+func withParams(next http.Handler) http.Handler {
23 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
24 		ctx := r.Context()
25 		cfg := config.FromContext(ctx)
26@@ -97,7 +97,8 @@ func withParams(h http.Handler) http.Handler {
27 		// Add repo suffix (.git)
28 		r.URL.Path = fmt.Sprintf("%s.git/%s", repo, vars["file"])
29 		r = mux.SetURLVars(r, vars)
30-		h.ServeHTTP(w, r)
31+
32+		next.ServeHTTP(w, r)
33 	})
34 }
35 
36@@ -111,7 +112,7 @@ func GitController(_ context.Context, r *mux.Router) {
37 	}
38 
39 	// Handle go-get
40-	r.Handle(basePrefix, withParams(withAccess(GoGetHandler{}))).Methods(http.MethodGet)
41+	r.Handle(basePrefix, withParams(withAccess(http.HandlerFunc(GoGetHandler)))).Methods(http.MethodGet)
42 }
43 
44 var gitRoutes = []GitRoute{
45diff --git a/pkg/web/goget.go b/pkg/web/goget.go
46index d8e65a400fed5bd4ed6752903a494c92026ebc3d..3c9c49719c0d44ad30fdef5dc9a44492d9e15497 100644
47--- a/pkg/web/goget.go
48+++ b/pkg/web/goget.go
49@@ -36,11 +36,7 @@ Redirecting to docs at <a href="https://godoc.org/{{ .ImportRoot }}/{{ .Repo }}"
50 `))
51 
52 // GoGetHandler handles go get requests.
53-type GoGetHandler struct{}
54-
55-var _ http.Handler = (*GoGetHandler)(nil)
56-
57-func (g GoGetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
58+func GoGetHandler(w http.ResponseWriter, r *http.Request) {
59 	ctx := r.Context()
60 	cfg := config.FromContext(ctx)
61 	be := backend.FromContext(ctx)
62diff --git a/pkg/web/logging.go b/pkg/web/logging.go
63index 70a3671d5b8af8c1b90e143a40fd7861ab6a4a4a..956ad9e9c160e2e411b7a4510c431ba0c880484d 100644
64--- a/pkg/web/logging.go
65+++ b/pkg/web/logging.go
66@@ -40,6 +40,11 @@ func (r *logWriter) WriteHeader(code int) {
67 	r.ResponseWriter.WriteHeader(code)
68 }
69 
70+// Unwrap returns the underlying http.ResponseWriter.
71+func (r *logWriter) Unwrap() http.ResponseWriter {
72+	return r.ResponseWriter
73+}
74+
75 // Flush implements http.Flusher.
76 func (r *logWriter) Flush() {
77 	if f, ok := r.ResponseWriter.(http.Flusher); ok {
78diff --git a/pkg/web/util.go b/pkg/web/util.go
79index 0e00357a26d4d1239ddad6ba248136d003ae15c5..412d0e00ef14b545fc042462b63bf12626ea7cc5 100644
80--- a/pkg/web/util.go
81+++ b/pkg/web/util.go
82@@ -8,7 +8,7 @@ import (
83 
84 func renderStatus(code int) http.HandlerFunc {
85 	return func(w http.ResponseWriter, _ *http.Request) {
86-		io.WriteString(w, fmt.Sprintf("%d %s", code, http.StatusText(code))) // nolint: errcheck
87 		w.WriteHeader(code)
88+		io.WriteString(w, fmt.Sprintf("%d %s", code, http.StatusText(code))) // nolint: errcheck
89 	}
90 }