diff --git a/api/api.go b/api/api.go index 3951ed13d63..95fcd734425 100644 --- a/api/api.go +++ b/api/api.go @@ -5,6 +5,7 @@ import ( "compress/gzip" "crypto/tls" "encoding/json" + "errors" "fmt" "io" "net" @@ -930,8 +931,16 @@ func parseWriteMeta(resp *http.Response, q *WriteMeta) error { // decodeBody is used to JSON decode a body func decodeBody(resp *http.Response, out interface{}) error { - dec := json.NewDecoder(resp.Body) - return dec.Decode(out) + switch resp.ContentLength { + case 0: + if out == nil { + return nil + } + return errors.New("Got 0 byte response with non-nil decode object") + default: + dec := json.NewDecoder(resp.Body) + return dec.Decode(out) + } } // encodeBody is used to encode a request body diff --git a/api/nodes.go b/api/nodes.go index 4a264eb4d33..7072dadc3f7 100644 --- a/api/nodes.go +++ b/api/nodes.go @@ -413,17 +413,15 @@ func (n *Nodes) Stats(nodeID string, q *QueryOptions) (*HostStats, error) { } func (n *Nodes) GC(nodeID string, q *QueryOptions) error { - var resp struct{} path := fmt.Sprintf("/v1/client/gc?node_id=%s", nodeID) - _, err := n.client.query(path, &resp, q) + _, err := n.client.query(path, nil, q) return err } // TODO Add tests func (n *Nodes) GcAlloc(allocID string, q *QueryOptions) error { - var resp struct{} path := fmt.Sprintf("/v1/client/allocation/%s/gc", allocID) - _, err := n.client.query(path, &resp, q) + _, err := n.client.query(path, nil, q) return err }