SimpleHttpResponse generateResponse(final HttpRequest request, final HttpCacheEntry entry) throws ResourceIOException {
        final Instant now = Instant.now();
        final SimpleHttpResponse response = new SimpleHttpResponse(entry.getStatus());

        response.setHeaders(entry.getHeaders());

        if (responseShouldContainEntity(request, entry)) {
            final Resource resource = entry.getResource();
            final Header h = entry.getFirstHeader(HttpHeaders.CONTENT_TYPE);
            final ContentType contentType = h != null ? ContentType.parse(h.getValue()) : null;
            final byte[] content = resource.get();
            generateContentLength(response, content);
            response.setBody(content, contentType);
        }

        final TimeValue age = this.validityStrategy.getCurrentAge(entry, now);
        if (TimeValue.isPositive(age)) {
            if (age.compareTo(CacheSupport.MAX_AGE) >= 0) {
                response.setHeader(HttpHeaders.AGE, Long.toString(CacheSupport.MAX_AGE.toSeconds()));
            } else {
                response.setHeader(HttpHeaders.AGE, Long.toString(age.toSeconds()));
            }
        }

        return response;
    }
If it is legal to use cached content in response response to the {@link HttpRequest} then
generate an {@link HttpResponse} based on {@link HttpCacheEntry}.
@param request {@link HttpRequest} to generate the response for
@param entry {@link HttpCacheEntry} to transform into an {@link HttpResponse}
@return {@link SimpleHttpResponse} constructed response
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachedHttpResponseGenerator.java