Skip to content

Commit da95cde

Browse files
joeybloggsjoeybloggs
authored andcommitted
add one more command middleware handler pattern func(http.ResponseWriter, *http.Request, http.Handler)
1 parent c01b9c8 commit da95cde

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

context_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,18 @@ func TestNativeHandlersAndParseForm(t *testing.T) {
271271
code, body = request(GET, "/chain-handler", l6)
272272
Equal(t, code, http.StatusOK)
273273
Equal(t, body, "aok")
274+
275+
l7 := New()
276+
l7.Get("/chain-handler", func(w http.ResponseWriter, r *http.Request, next http.Handler) {
277+
w.Write([]byte("a"))
278+
next.ServeHTTP(w, r)
279+
}, func(c Context) {
280+
c.Response().Write([]byte("ok"))
281+
})
282+
283+
code, body = request(GET, "/chain-handler", l7)
284+
Equal(t, code, http.StatusOK)
285+
Equal(t, body, "aok")
274286
}
275287

276288
func TestNativeHandlersAndParseMultiPartForm(t *testing.T) {

lars.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ func New() *LARS {
194194
}
195195

196196
l.routeGroup.lars = l
197-
// l.router = newRouter(l)
198197
l.pool.New = func() interface{} {
199198

200199
c := l.contextFunc(l)

util.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"runtime"
99
)
1010

11-
// NativeChainHandler is used in native handler chains
12-
// example using nosurf crsf middleware nosurf.NewPure(lars.NativeChainHandlerFunc)
11+
// NativeChainHandler is used in native handler chain middleware
12+
// example using nosurf crsf middleware nosurf.NewPure(lars.NativeChainHandler)
1313
var NativeChainHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1414

1515
c := GetContext(w)
@@ -73,7 +73,15 @@ func (l *LARS) wrapHandler(h Handler) HandlerFunc {
7373
}
7474
}
7575

76-
case func(handler http.Handler) http.Handler:
76+
case func(http.ResponseWriter, *http.Request, http.Handler):
77+
78+
return func(c Context) {
79+
ctx := c.BaseContext()
80+
81+
h(ctx.response, ctx.request, NativeChainHandler)
82+
}
83+
84+
case func(http.Handler) http.Handler:
7785

7886
hf := h(NativeChainHandler)
7987

0 commit comments

Comments
 (0)