Skip to content

Commit 4bf2aac

Browse files
committed
make sure Context sets required fields
While working on getting the [Go HTTP Routing Benchmark](https://github.com/julienschmidt/go-http-routing-benchmark) to compile / run, an issue with the `bear` package was being observed. Specifically, both the `http.ResponseWriter` and `*http.Request` sent to the HandleFunc were set to `nil`. Upon digging in to the codebase it was found that these two `Context{}` structs were being created incorrectly. It may be worth mentioning that I am not a user of `bear`, so I wouldn't be able to determine whether these are the right changes to be making. This should probably also have a regression test written for it. Please let me know if any thing else is needed to merge this changeset.
1 parent 5df0663 commit 4bf2aac

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

mux.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,23 @@ func (mux *Mux) ServeHTTP(res http.ResponseWriter, req *http.Request) {
128128
// root is a special case because it is the top node in the tree
129129
if req.URL.Path == slash || req.URL.Path == empty {
130130
if nil != tr.handlers { // root match
131-
(&Context{handler: -1, mux: mux, tree: tr}).Next()
131+
(&Context{
132+
handler: -1,
133+
mux: mux,
134+
tree: tr,
135+
ResponseWriter: res,
136+
Request: req,
137+
}).Next()
132138
return
133139
} else if wild := tr.children[wildcard]; nil != wild {
134140
// root level wildcard pattern match
135-
(&Context{handler: -1, mux: mux, tree: wild}).Next()
141+
(&Context{
142+
handler: -1,
143+
mux: mux,
144+
tree: wild,
145+
ResponseWriter: res,
146+
Request: req,
147+
}).Next()
136148
return
137149
}
138150
http.NotFound(res, req)

0 commit comments

Comments
 (0)