Cache-Control on dynamic generated images?

299 views
Skip to first unread message

Alex Dong

unread,
Jul 8, 2008, 1:20:09 AM7/8/08
to Google App Engine
Hi everyone:

Any idea on how can I add Cache-Control http header to the dynamically
generated images?

For the static files, Google offers a default one:

curl -I http://wuic.appspot.com/static/styles.css
{{{
HTTP/1.1 200 OK
Date: Tue, 08 Jul 2008 05:17:27 GMT
Expires: Tue, 08 Jul 2008 05:27:27 GMT
Cache-Control: public, max-age=600
Content-Type: text/css
Server: Google Frontend
Content-Length: 7802
}}}


But for the dynamic image file, here is what I get:
{{{
curl -I http://wuic.appspot.com/photo/6930.jpg
HTTP/1.1 405 Method Not Allowed
Content-Type: text/html; charset=UTF-8
Cache-Control: no-cache
Date: Tue, 08 Jul 2008 05:16:40 GMT
Server: Google Frontend
Content-Length: 328
}}}

This will be a win-win to both Google and GAE users.

Alex

Alex Dong

unread,
Jul 8, 2008, 2:31:29 AM7/8/08
to Google App Engine
Ok, after a bit search, I've got it working:
{{{
self.response.headers.add_header("Expires", "Thu, 01 Dec 2014 16")
self.response.headers["Cache-Control"] = "public, max-age=3660000"
self.response.headers['Content-Type'] = 'image/jpg'
self.response.out.write(photo.blob)
}}}
By default, the 'Cache-Control' is 'no-cache', so instead of
`add_header`, we'll need to overwrite it.

=================

With this problem solved, anyone knows how to assign a bit longer
expires time to the files in static folder?

Alex


On Jul 8, 1:20 pm, Alex Dong <alex.d...@gmail.com> wrote:
> Hi everyone:
>
> Any idea on how can I add Cache-Control http header to the dynamically
> generated images?
>
> For the static files, Google offers a default one:
>
> curl -Ihttp://wuic.appspot.com/static/styles.css
> {{{
> HTTP/1.1 200 OK
> Date: Tue, 08 Jul 2008 05:17:27 GMT
> Expires: Tue, 08 Jul 2008 05:27:27 GMT
> Cache-Control: public, max-age=600
> Content-Type: text/css
> Server: Google Frontend
> Content-Length: 7802
>
> }}}
>
> But for the dynamic image file, here is what I get:
> {{{
> curl -Ihttp://wuic.appspot.com/photo/6930.jpg

Blixt

unread,
Jul 8, 2008, 2:35:30 AM7/8/08
to Google App Engine
This part of the documentation should be of interest to you:
http://code.google.com/appengine/docs/configuringanapp.html#Static_File_Handlers

Alex Dong

unread,
Jul 8, 2008, 9:56:44 PM7/8/08
to Google App Engine
oh, Blixt, thanks a lot.

On Jul 8, 2:35 pm, Blixt <andreasbl...@gmail.com> wrote:
> This part of the documentation should be of interest to you:http://code.google.com/appengine/docs/configuringanapp.html#Static_Fi...
Reply all
Reply to author
Forward
0 new messages