mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-12-02 11:02:16 +00:00
Update go-restful to include emicklei/go-restful#197
This commit is contained in:
7
Godeps/_workspace/src/github.com/emicklei/go-restful/response.go
generated
vendored
7
Godeps/_workspace/src/github.com/emicklei/go-restful/response.go
generated
vendored
@@ -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)
|
||||
}
|
||||
|
||||
4
Godeps/_workspace/src/github.com/emicklei/go-restful/route.go
generated
vendored
4
Godeps/_workspace/src/github.com/emicklei/go-restful/route.go
generated
vendored
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
11
Godeps/_workspace/src/github.com/emicklei/go-restful/route_test.go
generated
vendored
11
Godeps/_workspace/src/github.com/emicklei/go-restful/route_test.go
generated
vendored
@@ -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"}}
|
||||
|
||||
Reference in New Issue
Block a user