@cryptotaxi247 / kubo / commits / 29b96b64a

commands/http: Made Handler set request contexts

Matt Bell committed Oct 27, 2014 at 18:14 UTC 29b96b64a58c4e1638e835954fb451dc39b9111f
1 file changed +7 -4
commands/http/handler.go
+7 -4
@@ -9,9 +9,9 @@ import (
9 "github.com/jbenet/go-ipfs/core/commands"
10 )
11
12 -type Handler struct{}
13 -
14 -// TODO: store ipfsnode context
12 +type Handler struct {
13 + Ctx cmds.Context
14 +}
15
16 func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
17 path := strings.Split(r.URL.Path, "/")[3:]
@@ -27,8 +27,11 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
27 return
28 }
29
30 - // build the Request and call the command
30 + // build the Request
31 req := cmds.NewRequest(path, opts, nil, nil)
32 + req.SetContext(i.Ctx)
33 +
34 + // call the command
35 res := commands.Root.Call(req)
36
37 // set the Content-Type based on res output