about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-03-18 09:05:47 +0000
committerEric Wong <normalperson@yhbt.net>2011-03-18 09:12:18 +0000
commitb8d44ff60c5cd6db6b971e2206cf18b5420a95cb (patch)
treebc09524c2aeac02a6b4eec4a3a3f86b92fb7b312
parent7c7e34dab18331082fe7b703b9bbdd40ea5bcbf6 (diff)
downloadraindrops-b8d44ff60c5cd6db6b971e2206cf18b5420a95cb.tar.gz
We know exactly when to invalidate based on the delay :)
-rw-r--r--lib/raindrops/watcher.rb12
-rw-r--r--test/test_watcher.rb14
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/raindrops/watcher.rb b/lib/raindrops/watcher.rb
index 52a8eff..3c724b9 100644
--- a/lib/raindrops/watcher.rb
+++ b/lib/raindrops/watcher.rb
@@ -168,14 +168,14 @@ class Raindrops::Watcher
   def active_stats(addr) # :nodoc:
     @lock.synchronize do
       tmp = @active[addr] or return
-      [ @resets[addr], tmp.dup ]
+      [ @snapshot[0], @resets[addr], tmp.dup ]
     end
   end
 
   def queued_stats(addr) # :nodoc:
     @lock.synchronize do
       tmp = @queued[addr] or return
-      [ @resets[addr], tmp.dup ]
+      [ @snapshot[0], @resets[addr], tmp.dup ]
     end
   end
 
@@ -200,16 +200,17 @@ class Raindrops::Watcher
   end
 
   def histogram_txt(agg)
-    reset_at, agg = *agg
+    updated_at, reset_at, agg = *agg
     headers = agg_to_hash(reset_at, agg)
     body = agg.to_s
     headers["Content-Type"] = "text/plain"
+    headers["Expires"] = (updated_at + @delay).httpdate
     headers["Content-Length"] = bytesize(body).to_s
     [ 200, headers, [ body ] ]
   end
 
   def histogram_html(agg, addr)
-    reset_at, agg = *agg
+    updated_at, reset_at, agg = *agg
     headers = agg_to_hash(reset_at, agg)
     body = "<html>" \
       "<head><title>#{hostname} - #{escape_html addr}</title></head>" \
@@ -221,6 +222,7 @@ class Raindrops::Watcher
       "<input type='submit' name='x' value='reset' /></form>" \
       "</body>"
     headers["Content-Type"] = "text/html"
+    headers["Expires"] = (updated_at + @delay).httpdate
     headers["Content-Length"] = bytesize(body).to_s
     [ 200, headers, [ body ] ]
   end
@@ -286,6 +288,7 @@ class Raindrops::Watcher
     headers = {
       "Content-Type" => "text/html",
       "Last-Modified" => updated_at.httpdate,
+      "Expires" => (updated_at + @delay).httpdate,
     }
     body = "<html><head>" \
       "<title>#{hostname} - all interfaces</title>" \
@@ -342,6 +345,7 @@ class Raindrops::Watcher
       headers = {
         "Content-Type" => "text/plain",
         "Cache-Control" => "no-transform",
+        "Expires" => Time.at(0).httpdate,
       }
       headers["Transfer-Encoding"] = "chunked" if @chunk
       [ 200, headers, self ]
diff --git a/test/test_watcher.rb b/test/test_watcher.rb
index f353862..86c97d8 100644
--- a/test/test_watcher.rb
+++ b/test/test_watcher.rb
@@ -50,6 +50,20 @@ class TestWatcher < Test::Unit::TestCase
     check_headers(resp.headers)
   end
 
+  def test_queued_txt
+    resp = @req.get "/queued/#@addr.txt"
+    assert_equal 200, resp.status.to_i
+    assert_equal "text/plain", resp.headers["Content-Type"]
+    check_headers(resp.headers)
+  end
+
+  def test_queued_html
+    resp = @req.get "/queued/#@addr.html"
+    assert_equal 200, resp.status.to_i
+    assert_equal "text/html", resp.headers["Content-Type"]
+    check_headers(resp.headers)
+  end
+
   def test_reset
     resp = @req.post "/reset/#@addr"
     assert_equal 302, resp.status.to_i