mirror of https://github.com/k3s-io/k3s
Merge pull request #6062 from superbrothers/update-go-restful
Update go-restful to include emicklei/go-restful#197pull/6/head
commit
41fbad219c
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"}}
|
||||
|
|
Loading…
Reference in New Issue