Bug 388926 - Use If-Modified-Since when checking for updates in ICS calendars. r=philipp
authorLukas Rechberger <lukas@rechberger.priv.at>
Tue, 21 Jul 2015 14:04:35 +0200
changeset 18231 84b210b8fa1defa4f2633e02b87e568bfbd65eae
parent 18230 a5e14ae6598a1dcc614a2840865c41896c76820b
child 18232 fbc2a9c68d93a89fb49f9611cb9db4f328853f27
push id11196
push useraleth@instantbird.org
push dateSun, 09 Aug 2015 22:37:29 +0000
treeherdercomm-central@863ae7f4ea84 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs388926
Bug 388926 - Use If-Modified-Since when checking for updates in ICS calendars. r=philipp
calendar/providers/ics/calICSCalendar.js
--- a/calendar/providers/ics/calICSCalendar.js
+++ b/calendar/providers/ics/calICSCalendar.js
@@ -907,22 +907,26 @@ dummyHooks.prototype = {
 };
 
 function httpHooks(calendar) {
     this.mCalendar = calendar;
 }
 
 httpHooks.prototype = {
     onBeforeGet: function(aChannel, aForceRefresh) {
+        var httpchannel = aChannel.QueryInterface(Components.interfaces.nsIHttpChannel);
+        httpchannel.setRequestHeader("Accept", "text/calendar,text/plain;q=0.8,*/*;q=0.5", false);
+
         if (this.mEtag && !aForceRefresh) {
-            var httpchannel = aChannel.QueryInterface(Components.interfaces.nsIHttpChannel);
             // Somehow the webdav header 'If' doesn't work on apache when
             // passing in a Not, so use the http version here.
-            httpchannel.setRequestHeader("Accept", "text/calendar,text/plain;q=0.8,*/*;q=0.5", false);
             httpchannel.setRequestHeader("If-None-Match", this.mEtag, false);
+        } else if (!aForceRefresh && this.mLastModified) {
+            // Only send 'If-Modified-Since' if no ETag is available
+            httpchannel.setRequestHeader("If-Modified-Since", this.mLastModified, false);
         }
 
         return true;
     },
 
     onAfterGet: function(aChannel, aForceRefresh) {
         let httpchannel = aChannel.QueryInterface(Components.interfaces.nsIHttpChannel);
         let responseStatus = 0;
@@ -961,16 +965,23 @@ httpHooks.prototype = {
         }
 
         try {
             this.mEtag = httpchannel.getResponseHeader("ETag");
         } catch(e) {
             // No etag header. Now what?
             this.mEtag = null;
         }
+
+        try {
+            this.mLastModified = httpchannel.getResponseHeader("Last-Modified");
+        } catch(e) {
+            this.mLastModified = null;
+        }
+
         return true;
     },
 
     onBeforePut: function(aChannel) {
         if (this.mEtag) {
             var httpchannel = aChannel.QueryInterface(Components.interfaces.nsIHttpChannel);
 
             // Apache doesn't work correctly with if-match on a PUT method,