Play! seems to ignore setHeader Cache-Control

2,124 views
Skip to first unread message

Ivan San José García

unread,
Feb 4, 2011, 9:51:50 AM2/4/11
to play-fr...@googlegroups.com
I serve an image from a Controller setting Cache-Control header to no-cache:

public static void getPhoto(String userId) {
Logger.debug("GETPHOTO");
Usuario connectedUser = Usuario.getById(Security.connected());
Usuario u = Usuario.getById(userId);
notFoundIfNull(u);

if (!u.canView(connectedUser))
forbidden();

response.setHeader("Cache-Control", "no-cache");
renderBinary(u.getPhoto());
}

But, the response of Play! server was this:

Cache-Control:max-age=3600
Content-Disposition:inline;
filename*=utf-8''8e055b51-49f2-490e-93bf-454a2f1c2eeb.jpg;
filename="8e055b51-49f2-490e-93bf-454a2f1c2eeb.jpg"
Content-Type:image/jpeg
ETag:"1288884338000-1691088053"
Server:Play! Framework;1.1;prod

What's going on?

Ivan San José García

unread,
Feb 4, 2011, 10:24:28 AM2/4/11
to play-fr...@googlegroups.com
I'm trying to find in source code where Play! overrides Cache-Control
header, but, in the results of a grep -ri cache-control framework/src/
only appears framework/src/play/server/ServletWrapper.java. But is it
the wrapper for servlet container no?
Where Play! puts the Cache-Control header?

El día 4 de febrero de 2011 15:51, Ivan San José García
<iva...@gmail.com> escribió:

Pascal Voitot Dev

unread,
Feb 4, 2011, 10:29:13 AM2/4/11
to play-fr...@googlegroups.com
grep -r "cache" *

server/ServletWrapper.java:                    servletResponse.setHeader("Cache-Control", "no-cache");
server/ServletWrapper.java:                        servletResponse.setHeader("Cache-Control", "max-age=" + Play.configuration.getProperty("http.cacheControl", "3600"));
server/ServletWrapper.java:        if (!response.headers.containsKey("cache-control")) {
server/ServletWrapper.java:            servletResponse.setHeader("Cache-Control", "no-cache");
server/PlayHandler.java:            nettyResponse.setHeader(CACHE_CONTROL, "no-cache");
server/PlayHandler.java:            httpResponse.setHeader(CACHE_CONTROL, "no-cache");
server/PlayHandler.java:            String maxAge = Play.configuration.getProperty("http.cacheControl", "3600");
server/PlayHandler.java:                httpResponse.setHeader(CACHE_CONTROL, "no-cache");

Apparently PlayHandler sets some "no-cache" header also!

Pascal

2011/2/4 Ivan San José García <iva...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


Ivan San José García

unread,
Feb 4, 2011, 10:43:51 AM2/4/11
to play-fr...@googlegroups.com
Thanks Pascal!

I think that addEtag() method override my Cache-Control header in prod mode:

When renderBinary() is applied to a File object, the method addEtag()
was called in PlayHandler class:

private static HttpResponse addEtag(HttpRequest nettyRequest,
HttpResponse httpResponse, File file) {
if (Play.mode == Play.Mode.DEV) {
httpResponse.setHeader(CACHE_CONTROL, "no-cache");
} else {


String maxAge =
Play.configuration.getProperty("http.cacheControl", "3600");

if (maxAge.equals("0")) {
httpResponse.setHeader(CACHE_CONTROL, "no-cache");
} else {
httpResponse.setHeader(CACHE_CONTROL, "max-age=" + maxAge);
}
}

And there, in production mode, overwrites any Cache-Control header
that was setted with request.setHeader() in a Controller.

Is this a bug?

2011/2/4 Pascal Voitot Dev <pascal.v...@gmail.com>:

Ivan San José García

unread,
Feb 7, 2011, 3:20:38 AM2/7/11
to play-fr...@googlegroups.com
I'm sorry to insist but I'm very confused with this issue. Anyone can help me?

Additionally, I think that Play! doesn't handle well the ETag header.
See this situation:

- Request:
If-None-Match:"1296821490000--1382045956"

- Response:
200 OK
ETag:"1296821490000--1382045956"

I think this is wrong. Because, if the content requested didn't
change, Play! must response with a 304 Not Modified, and not with the
same content again.

I'm wrong or it's a bug? I'm using Play! 1.1.

El día 4 de febrero de 2011 16:43, Ivan San José García

Ivan San José García

unread,
Apr 25, 2011, 10:14:26 AM4/25/11
to play-fr...@googlegroups.com
After many tries, I have investigated about ETag, and Play! seems to
use it correctly.

Although, the bug about that "Cache-Control" was overwritten when use
renderBinary(), is true. So, I have created a ticket with a patch:
http://play.lighthouseapp.com/projects/57987-play-framework/tickets/772-overwritten-of-cache-control-header-when-apply-renderbinary-to-a-file

El día 7 de febrero de 2011 09:20, Ivan San José García

Reply all
Reply to author
Forward
0 new messages