Skip to content

Commit

Permalink
Added Etag
Browse files Browse the repository at this point in the history
  • Loading branch information
ptarjan committed Dec 14, 2009
1 parent cd3678f commit bd14a3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion index.yaml
Expand Up @@ -10,7 +10,6 @@ indexes:
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.

# Used 114 times in query history.
- kind: Icon
properties:
- name: set
Expand Down
14 changes: 12 additions & 2 deletions main.py
@@ -1,8 +1,9 @@
# Paul Tarjan : http://paulisageek.com

import os
import mimetypes
import hashlib
import logging
import mimetypes
import os
import simplejson
import random
from urllib import unquote
Expand Down Expand Up @@ -263,6 +264,15 @@ def respond_image(self, image):
then = timedelta(hours=hours) + datetime.now()
self.response.headers['Expires'] = then.strftime("%a, %d %b %Y %H:%M:%S GMT")
self.response.headers['Cache-Control'] = 'max-age=%d' % int(3600 * hours)

checksum = hashlib.md5(image).hexdigest()
self.response.headers['ETag'] = checksum
try:
if self.request.headers['If-None-Match'] == checksum :
self.response.set_status(304)
return
except KeyError:
pass
self.response.out.write(image)
return True

Expand Down

0 comments on commit bd14a3a

Please sign in to comment.