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.
(prefix string, body []byte)
| 938 | // allocating a new string for the body output unless necessary. Uses a simple heuristic to determine |
| 939 | // whether the body is printable. |
| 940 | func glogBody(prefix string, body []byte) { |
| 941 | if klog.V(8) { |
| 942 | if bytes.IndexFunc(body, func(r rune) bool { |
| 943 | return r < 0x0a |
| 944 | }) != -1 { |
| 945 | klog.Infof("%s:\n%s", prefix, truncateBody(hex.Dump(body))) |
| 946 | } else { |
| 947 | klog.Infof("%s: %s", prefix, truncateBody(string(body))) |
| 948 | } |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | // maxUnstructuredResponseTextBytes is an upper bound on how much output to include in the unstructured error. |
| 953 | const maxUnstructuredResponseTextBytes = 2048 |
no test coverage detected