body() 返回的当前 response 的 body
public ResponseBody body() {
return body;
}
peekBody() 返回的是一个新的 response 的 body
/**
* Peeks up to {@code byteCount} bytes from the response body and returns them as a new response
* body. If fewer than {@code byteCount} bytes are in the response body, the full response body is
* returned. If more than {@code byteCount} bytes are in the response body, the returned value
* will be truncated to {@code byteCount} bytes.
*
* <p>It is an error to call this method after the body has been consumed.
*
* <p><strong>Warning:</strong> this method loads the requested bytes into memory. Most
* applications should set a modest limit on {@code byteCount}, such as 1 MiB.
*/
public ResponseBody peekBody(long byteCount) throws IOException {
BufferedSource source = body.source();
source.request(byteCount);
Buffer copy = source.buffer().clone();
// There may be more than byteCount bytes in source.buffer(). If there is, return a prefix.
Buffer result;
if (copy.size() > byteCount) {
result = new Buffer();
result.write(copy, byteCount);
copy.clear();
} else {
result = copy;
}
return ResponseBody.create(body.contentType(), result.size(), result);
}
peekBody 会传入一个byteCount 参数 当元body的 长度大于byteCount 返回的新body对象就只会包含byteCount长度的 返回值。