From 1bee791e5bf51828546dcd491122c711a69abbd8 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 26 Oct 2010 19:27:29 +0200 Subject: [PATCH] Make sure max-age is an integer (as specified by RFC2616). Fixes #106. --- lib/sinatra/base.rb | 6 +++++- test/helpers_test.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 5e88153e..83c5b3b6 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -264,7 +264,11 @@ module Sinatra end values = values.map { |value| value.to_s.tr('_','-') } - hash.each { |k,v| values << [k.to_s.tr('_', '-'), v].join('=') } + hash.each do |key, value| + key = key.to_s.tr('_', '-') + value = value.to_i if key == "max-age" + values << [key, value].join('=') + end response['Cache-Control'] = values.join(', ') if values.any? end diff --git a/test/helpers_test.rb b/test/helpers_test.rb index a12f78d5..efde3c61 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -426,7 +426,7 @@ class HelpersTest < Test::Unit::TestCase setup do mock_app { get '/' do - cache_control :public, :no_cache, :max_age => 60 + cache_control :public, :no_cache, :max_age => 60.0 'Hello World' end }