published by bot

(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 5b2823adb9a8777f7819884fa79a6e1daa26b9c2
This commit is contained in:
Kubernetes Publisher
2016-12-17 15:19:41 +00:00
parent dd9bc19bbb
commit 5fe6fc56cb
135 changed files with 20762 additions and 148682 deletions

View File

@@ -540,10 +540,10 @@ func (r *Request) Body(obj interface{}) *Request {
r.err = err
return r
}
glog.V(8).Infof("Request Body: %#v", string(data))
glogBody("Request Body", data)
r.body = bytes.NewReader(data)
case []byte:
glog.V(8).Infof("Request Body: %#v", string(t))
glogBody("Request Body", t)
r.body = bytes.NewReader(t)
case io.Reader:
r.body = t
@@ -557,7 +557,7 @@ func (r *Request) Body(obj interface{}) *Request {
r.err = err
return r
}
glog.V(8).Infof("Request Body: %#v", string(data))
glogBody("Request Body", data)
r.body = bytes.NewReader(data)
r.SetHeader("Content-Type", r.content.ContentType)
default:
@@ -878,6 +878,7 @@ func (r *Request) DoRaw() ([]byte, error) {
var result Result
err := r.request(func(req *http.Request, resp *http.Response) {
result.body, result.err = ioutil.ReadAll(resp.Body)
glogBody("Response Body", result.body)
if resp.StatusCode < http.StatusOK || resp.StatusCode > http.StatusPartialContent {
result.err = r.transformUnstructuredResponseError(resp, req, result.body)
}
@@ -897,15 +898,7 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
}
}
if glog.V(8) {
if bytes.IndexFunc(body, func(r rune) bool {
return r < 0x0a
}) != -1 {
glog.Infof("Response Body:\n%s", hex.Dump(body))
} else {
glog.Infof("Response Body: %s", string(body))
}
}
glogBody("Response Body", body)
// verify the content type is accurate
contentType := resp.Header.Get("Content-Type")
@@ -957,6 +950,21 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
}
}
// glogBody logs a body output that could be either JSON or protobuf. It explicitly guards against
// allocating a new string for the body output unless necessary. Uses a simple heuristic to determine
// whether the body is printable.
func glogBody(prefix string, body []byte) {
if glog.V(8) {
if bytes.IndexFunc(body, func(r rune) bool {
return r < 0x0a
}) != -1 {
glog.Infof("%s:\n%s", prefix, hex.Dump(body))
} else {
glog.Infof("%s: %s", prefix, string(body))
}
}
}
// maxUnstructuredResponseTextBytes is an upper bound on how much output to include in the unstructured error.
const maxUnstructuredResponseTextBytes = 2048
@@ -994,7 +1002,6 @@ func (r *Request) newUnstructuredResponseError(body []byte, isTextResponse bool,
if len(body) > maxUnstructuredResponseTextBytes {
body = body[:maxUnstructuredResponseTextBytes]
}
glog.V(8).Infof("Response Body: %#v", string(body))
message := "unknown"
if isTextResponse {