Skip to content
This repository
Browse code

BugFix in ConditionalGet; don't crash when we get a malformed HTTP_IF…

…_MODIFIED_SINCE timestamp
  • Loading branch information...
commit 68dd85f6288ac8014c395c801c254ba69b29efbb 1 parent 4425e37
Nicholas Mulder authored August 31, 2011
1  lib/rack/conditionalget.rb
@@ -56,6 +56,7 @@ def etag_matches?(none_match, headers)
56 56
 
57 57
     def modified_since?(modified_since, headers)
58 58
       last_modified = to_rfc2822(headers['Last-Modified']) and
  59
+        modified_since and
59 60
         modified_since >= last_modified
60 61
     end
61 62
 
12  test/spec_conditionalget.rb
@@ -83,4 +83,16 @@
83 83
     response.body.should.equal 'TEST'
84 84
   end
85 85
 
  86
+  should "not affect requests with malformed HTTP_IF_NONE_MATCH" do
  87
+    bad_timestamp = Time.now.strftime('%Y-%m-%d %H:%M:%S %z')
  88
+    app = Rack::ConditionalGet.new(lambda { |env|
  89
+      [200,{'Last-Modified'=>(Time.now - 3600).httpdate}, ['TEST']] })
  90
+
  91
+    response = Rack::MockRequest.new(app).
  92
+      get("/", 'HTTP_IF_MODIFIED_SINCE' => bad_timestamp)
  93
+
  94
+    response.status.should.equal 200
  95
+    response.body.should.equal 'TEST'
  96
+  end
  97
+
86 98
 end

0 notes on commit 68dd85f

Please sign in to comment.
Something went wrong with that request. Please try again.