# HG changeset patch # User Emmanuel Gil Peyrot # Date 1527885941 -7200 # Node ID 5b4e7db5943c25727107d32a20090d58e187eb46 # Parent 46d71b38bc160edcaf1afc25f6b3de8cb680c802 mod_http_avatar: Add caching support. diff -r 46d71b38bc16 -r 5b4e7db5943c mod_http_avatar/mod_http_avatar.lua --- a/mod_http_avatar/mod_http_avatar.lua Fri Jun 01 22:11:42 2018 +0200 +++ b/mod_http_avatar/mod_http_avatar.lua Fri Jun 01 22:45:41 2018 +0200 @@ -5,6 +5,7 @@ -- COPYING file in the source package for more information. local base64 = require"util.encodings".base64; +local sha1 = require"util.hashes".sha1; local st = require"util.stanza"; module:depends"http"; @@ -16,7 +17,7 @@ ]]; local function get_avatar(event, path) - local response = event.response; + local request, response = event.request, event.response; local photo_type, binval; local vcard, err = vcard_storage:get(path); if vcard then @@ -32,8 +33,14 @@ response.headers.content_type = "image/svg+xml"; return default_avatar; end + local avatar = base64.decode(binval); + local hash = sha1(avatar, true); + if request.headers.if_none_match == hash then + return 304; + end response.headers.content_type = photo_type; - return base64.decode(binval); + response.headers.etag = hash; + return avatar; end module:provides("http", {