Mercurial > prosody-modules
comparison mod_pubsub_feeds/mod_pubsub_feeds.lua @ 3047:7c55f05327a2
mod_pubsub_feeds: Use ETag instead of problematic If-Modified-Since
Because it set If-Modified-Since to the last poll time instead of the
exact value of Last-Modified in the last response, it would not work
with some HTTP servers.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 27 May 2018 15:51:05 +0200 |
parents | cae371544ff5 |
children | fe4194f10c75 |
comparison
equal
deleted
inserted
replaced
3046:d0db28768980 | 3047:7c55f05327a2 |
---|---|
13 -- Reference | 13 -- Reference |
14 -- http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.4.html | 14 -- http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.4.html |
15 | 15 |
16 local pubsub = module:depends"pubsub"; | 16 local pubsub = module:depends"pubsub"; |
17 | 17 |
18 local date, time = os.date, os.time; | 18 local time = os.time; |
19 local dt_parse, dt_datetime = require "util.datetime".parse, require "util.datetime".datetime; | 19 local dt_parse, dt_datetime = require "util.datetime".parse, require "util.datetime".datetime; |
20 local uuid = require "util.uuid".generate; | 20 local uuid = require "util.uuid".generate; |
21 local hmac_sha1 = require "util.hashes".hmac_sha1; | 21 local hmac_sha1 = require "util.hashes".hmac_sha1; |
22 local parse_xml = require "util.xml".parse; | 22 local parse_xml = require "util.xml".parse; |
23 local st = require "util.stanza"; | 23 local st = require "util.stanza"; |
145 end | 145 end |
146 end | 146 end |
147 | 147 |
148 function fetch(item, callback) -- HTTP Pull | 148 function fetch(item, callback) -- HTTP Pull |
149 local headers = { }; | 149 local headers = { }; |
150 if item.data and item.last_update then | 150 if item.data and item.etag then |
151 headers["If-Modified-Since"] = date("!%a, %d %b %Y %H:%M:%S %Z", item.last_update); | 151 headers["If-None-Match"] = item.etag; |
152 end | 152 end |
153 http.request(item.url, { headers = headers }, function(data, code) | 153 http.request(item.url, { headers = headers }, function(data, code, resp) |
154 if code == 200 then | 154 if code == 200 then |
155 item.data = data; | 155 item.data = data; |
156 if callback then callback(item) end | 156 if callback then callback(item) end |
157 item.last_update = time(); | 157 item.last_update = time(); |
158 if resp.headers then | |
159 item.etag = resp.headers.etag | |
160 end | |
158 elseif code == 304 then | 161 elseif code == 304 then |
159 item.last_update = time(); | 162 item.last_update = time(); |
160 end | 163 end |
161 end); | 164 end); |
162 end | 165 end |