docs: private Response cacheWritingResponse(final CacheRequest cacheRequest, Response response)
        throws IOException {
      // Some apps return a null body; for compatibility we treat that like a null cache request.
      if (cacheRequest == null) return response;
      Sink cacheBodyUnbuffered = cacheRequest.body();
      if (cacheBodyUnbuffered == null) return response;
  
      final BufferedSource source = response.body().source();
      final BufferedSink cacheBody = Okio.buffer(cacheBodyUnbuffered);
  
      Source cacheWritingSource = new Source() {
        boolean cacheRequestClosed;
  
        @Override public long read(Buffer sink, long byteCount) throws IOException {
          long bytesRead;
          try {
            bytesRead = source.read(sink, byteCount);
          } catch (IOException e) {
            if (!cacheRequestClosed) {
              cacheRequestClosed = true;
              cacheRequest.abort(); // Failed to write a complete cache response.
            }
            throw e;
          }
  
          if (bytesRead == -1) {
            if (!cacheRequestClosed) {
              cacheRequestClosed = true;
              cacheBody.close(); // The cache response is complete!
            }
            return -1;
          }
  
          sink.copyTo(cacheBody.buffer(), sink.size() - bytesRead, bytesRead);
          cacheBody.emitCompleteSegments();
          return bytesRead;
        }
  
        @Override public Timeout timeout() {
          return source.timeout();
        }
  
        @Override public void close() throws IOException {
          if (!cacheRequestClosed
              && !discard(this, ExchangeCodec.DISCARD_STREAM_TIMEOUT_MILLIS, MILLISECONDS)) {
            cacheRequestClosed = true;
            cacheRequest.abort();
          }
          source.close();
        }
      };
  
      String contentType = response.header("Content-Type");
      long contentLength = response.body().contentLength();
      return response.newBuilder()
          .body(new RealResponseBody(contentType, contentLength, Okio.buffer(cacheWritingSource)))
          .build();
    }