changcheng / wro4j

Automatically exported from code.google.com/p/wro4j
0 stars 0 forks source link

Missing cache header attributes in css images #529

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

WRO does not transmit cache header attributes for css images e.g. background 
images referenced in css style sheets. Look at method 
ResourceProxyRequestHandler.serverProxyResourceUri():

    final InputStream is = uriLocatorFactory.locate(resourceUri);
    final OutputStream outputStream = response.getOutputStream();

    response.setContentType(ContentTypeResolver.get(resourceUri,...));

    // ??? Missing cache attributes !!!

    int length = IOUtils.copy(is, outputStream);
    response.setContentLength(length);
    response.setStatus(HttpServletResponse.SC_OK);

    IOUtils.closeQuietly(outputStream);
    IOUtils.closeQuietly(is);

Furthermore, any header attribute should be set *before* the content body is 
written. 

What is the expected output? What do you see instead?

I suggest the following:

    response.setContentType(ContentTypeResolver.get(resourceUri,...));

    // Fixme: set cache header, etag, ...

    response.setStatus(HttpServletResponse.SC_OK);

    final OutputStream outputStream = response.getOutputStream();
    try {
      final InputStream is = uriLocatorFactory.locate(resourceUri);
      try {
        int length = IOUtils.copy(is, outputStream);
        response.setContentLength(length); // servlet engine may ignore this if content body is flushed to client
      } finally {
        IOUtils.closeQuietly(is);
      }
    } finally {
      IOUtils.closeQuietly(outputStream);
    }

What version of the product are you using? On what operating system?
WRO 1.4.8.1

Original issue reported on code.google.com by g...@inasys.de on 27 Aug 2012 at 8:06

GoogleCodeExporter commented 9 years ago

Original comment by alex.obj...@gmail.com on 27 Aug 2012 at 8:07

GoogleCodeExporter commented 9 years ago
The ETag header won't be added, since the resource content is not cached on the 
server-side and it would add an extra overhead to compute it on each request...

Original comment by alex.obj...@gmail.com on 30 Aug 2012 at 2:27

GoogleCodeExporter commented 9 years ago

Original comment by alex.obj...@gmail.com on 7 Sep 2012 at 8:03