commands/http: Made Handler set request contexts

This commit is contained in:
Matt Bell 2014-10-27 18:14:24 -07:00 committed by Juan Batiz-Benet
parent 289bce6bdb
commit 29b96b64a5

View File

@ -9,9 +9,9 @@ import (
"github.com/jbenet/go-ipfs/core/commands"
)
type Handler struct{}
// TODO: store ipfsnode context
type Handler struct {
Ctx cmds.Context
}
func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
path := strings.Split(r.URL.Path, "/")[3:]
@ -27,8 +27,11 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
// build the Request and call the command
// build the Request
req := cmds.NewRequest(path, opts, nil, nil)
req.SetContext(i.Ctx)
// call the command
res := commands.Root.Call(req)
// set the Content-Type based on res output