diff 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
line wrap: on
line diff
--- a/mod_pubsub_feeds/mod_pubsub_feeds.lua	Sat May 26 10:58:06 2018 +0200
+++ b/mod_pubsub_feeds/mod_pubsub_feeds.lua	Sun May 27 15:51:05 2018 +0200
@@ -15,7 +15,7 @@
 
 local pubsub = module:depends"pubsub";
 
-local date, time = os.date, os.time;
+local time = os.time;
 local dt_parse, dt_datetime = require "util.datetime".parse, require "util.datetime".datetime;
 local uuid = require "util.uuid".generate;
 local hmac_sha1 = require "util.hashes".hmac_sha1;
@@ -147,14 +147,17 @@
 
 function fetch(item, callback) -- HTTP Pull
 	local headers = { };
-	if item.data and item.last_update then
-		headers["If-Modified-Since"] = date("!%a, %d %b %Y %H:%M:%S %Z", item.last_update);
+	if item.data and item.etag then
+		headers["If-None-Match"] = item.etag;
 	end
-	http.request(item.url, { headers = headers }, function(data, code)
+	http.request(item.url, { headers = headers }, function(data, code, resp)
 		if code == 200 then
 			item.data = data;
 			if callback then callback(item) end
 			item.last_update = time();
+			if resp.headers then
+				item.etag = resp.headers.etag
+			end
 		elseif code == 304 then
 			item.last_update = time();
 		end