Skip to content

Commit

Permalink
Handle blank segments in Cache-Control header.
Browse files Browse the repository at this point in the history
  • Loading branch information
oggy committed Dec 22, 2010
1 parent 428ac19 commit 43c25a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rack/cache/cachecontrol.rb
Expand Up @@ -183,6 +183,7 @@ def to_s
def parse(value)
return if value.nil? || value.empty?
value.delete(' ').split(',').inject(self) do |hash,part|
next if part.empty?
name, value = part.split('=', 2)
hash[name.downcase] = (value || true) unless name.empty?
hash
Expand Down
6 changes: 6 additions & 0 deletions test/cachecontrol_test.rb
Expand Up @@ -49,6 +49,12 @@
cache_control['max-age'].should.equal '600'
end

it 'strips blank segments' do
cache_control = Rack::Cache::CacheControl.new('max-age=600,,max-stale=300')
cache_control['max-age'].should.equal '600'
cache_control['max-stale'].should.equal '300'
end

it 'removes all directives with #clear' do
cache_control = Rack::Cache::CacheControl.new('max-age=600, must-revalidate')
cache_control.clear
Expand Down

0 comments on commit 43c25a0

Please sign in to comment.