Commit 5589021a authored by Matt Bell's avatar Matt Bell

commands/http: Fixed panics when unmarshaling command output without a set Command.Type

parent 452f54a4
......@@ -153,8 +153,14 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
outputType := reflect.TypeOf(req.Command().Type)
for {
v := reflect.New(outputType).Interface()
err := dec.Decode(v)
var v interface{}
var err error
if outputType != nil {
v = reflect.New(outputType).Interface()
err = dec.Decode(v)
} else {
err = dec.Decode(&v)
}
if err != nil && err != io.EOF {
fmt.Println(err.Error())
return
......@@ -200,13 +206,20 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
} else {
outputType := reflect.TypeOf(req.Command().Type)
v := reflect.New(outputType).Interface()
err = dec.Decode(v)
var v interface{}
if outputType != nil {
v = reflect.New(outputType).Interface()
err = dec.Decode(v)
} else {
err = dec.Decode(&v)
}
if err != nil && err != io.EOF {
return nil, err
}
res.SetOutput(v)
if v != nil {
res.SetOutput(v)
}
}
return res, nil
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment