Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Guard against invalid if modified since headers

  • Loading branch information...
commit eff80f50531f7cc4005a1a973074cea47f0f5824 1 parent 76d3451
@mbj authored
View
6 lib/request/rack.rb
@@ -90,7 +90,11 @@ def query_params
#
def if_modified_since
value = @rack_env.fetch(IF_MODIFIED_SINCE) { return }
- Time.httpdate(value)
+ begin
+ Time.httpdate(value)
+ rescue ArgumentError
+ nil
+ end
end
memoize :if_modified_since
View
2  spec/shared/rack_env_accessor_behavior.rb
@@ -15,7 +15,7 @@
let(:env) { default_env.merge(rack_key => rack_key_value) }
- it { should be(expected_value) }
+ it { should eql(expected_value) }
it 'should not freeze the input env' do
subject
View
25 spec/unit/request/rack/if_modified_since_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe Request::Rack, '#if_modified_since' do
+ subject { object.if_modified_since }
+
+ let(:object) { described_class.new(env) }
+ let(:rack_key) { 'HTTP_IF_MODIFIED_SINCE' }
+
+ context 'if value is decodable' do
+ it_should_behave_like 'a rack env accessor' do
+
+ # Strip milliseconds
+ let(:time) { Time.httpdate(Time.now.httpdate) }
+ let(:rack_key_value) { time.httpdate }
+ let(:expected_value) { time }
+ end
+ end
+
+ context 'if value is not decodable' do
+ it_should_behave_like 'a rack env accessor' do
+ let(:rack_key_value) { 'foo' }
+ let(:expected_value) { nil }
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.