diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index ef883f187cc..ac3802231be 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -170,8 +170,8 @@ }, { "ImportPath": "github.com/emicklei/go-restful", - "Comment": "v1.1.3-26-g977ac8f", - "Rev": "977ac8fcbcd2ee33319246f7c91d4b426402dc70" + "Comment": "v1.1.3-29-gc68bc68", + "Rev": "c68bc68d7689f127ab554a42378aece0ea3df4b3" }, { "ImportPath": "github.com/evanphx/json-patch", diff --git a/Godeps/_workspace/src/github.com/emicklei/go-restful/response.go b/Godeps/_workspace/src/github.com/emicklei/go-restful/response.go index 0a3cbd556ca..04e21bbe496 100644 --- a/Godeps/_workspace/src/github.com/emicklei/go-restful/response.go +++ b/Godeps/_workspace/src/github.com/emicklei/go-restful/response.go @@ -150,6 +150,11 @@ func (r *Response) WriteAsXml(value interface{}) error { // WriteAsJson is a convenience method for writing a value in json func (r *Response) WriteAsJson(value interface{}) error { + return r.WriteJson(value, MIME_JSON) // no charset +} + +// WriteJson is a convenience method for writing a value in Json with a given Content-Type +func (r *Response) WriteJson(value interface{}, contentType string) error { var output []byte var err error @@ -165,7 +170,7 @@ func (r *Response) WriteAsJson(value interface{}) error { if err != nil { return r.WriteErrorString(http.StatusInternalServerError, err.Error()) } - r.Header().Set(HEADER_ContentType, MIME_JSON) + r.Header().Set(HEADER_ContentType, contentType) if r.statusCode > 0 { // a WriteHeader was intercepted r.ResponseWriter.WriteHeader(r.statusCode) } diff --git a/Godeps/_workspace/src/github.com/emicklei/go-restful/route.go b/Godeps/_workspace/src/github.com/emicklei/go-restful/route.go index 3b1e13ab9dc..f54e8622e3f 100644 --- a/Godeps/_workspace/src/github.com/emicklei/go-restful/route.go +++ b/Godeps/_workspace/src/github.com/emicklei/go-restful/route.go @@ -79,8 +79,8 @@ func (r Route) matchesAccept(mimeTypesWithQuality string) bool { if withoutQuality == "*/*" { return true } - for _, other := range r.Produces { - if other == withoutQuality { + for _, producibleType := range r.Produces { + if producibleType == "*/*" || producibleType == withoutQuality { return true } } diff --git a/Godeps/_workspace/src/github.com/emicklei/go-restful/route_test.go b/Godeps/_workspace/src/github.com/emicklei/go-restful/route_test.go index a416576187d..78b3be88fd3 100644 --- a/Godeps/_workspace/src/github.com/emicklei/go-restful/route_test.go +++ b/Godeps/_workspace/src/github.com/emicklei/go-restful/route_test.go @@ -31,6 +31,17 @@ func TestMatchesAcceptXml(t *testing.T) { } } +// accept should match produces +func TestMatchesAcceptAny(t *testing.T) { + r := Route{Produces: []string{"*/*"}} + if !r.matchesAccept("application/json") { + t.Errorf("accept should match json") + } + if !r.matchesAccept("application/xml") { + t.Errorf("accept should match xml") + } +} + // content type should match consumes func TestMatchesContentTypeXml(t *testing.T) { r := Route{Consumes: []string{"application/xml"}}