From c0a2fbc8b1f843bd8d450dae5396d803b90c552a Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Wed, 21 Jan 2009 11:37:56 -0800 Subject: [PATCH] Make static files work with Rack::Lint in the pipeline [#121] --- lib/sinatra/base.rb | 1 + test/static_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 489b4e77..d2d92bb5 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -142,6 +142,7 @@ module Sinatra class StaticFile < ::File #:nodoc: alias_method :to_path, :path def each + rewind while buf = read(8192) yield buf end diff --git a/test/static_test.rb b/test/static_test.rb index 2ff417bf..2dbca2d5 100644 --- a/test/static_test.rb +++ b/test/static_test.rb @@ -18,6 +18,16 @@ describe 'Static' do assert response.headers.include?('Last-Modified') end + it 'produces a body that can be iterated over multiple times' do + env = Rack::MockRequest.env_for("/#{F.basename(__FILE__)}") + status, headers, body = @app.call(env) + buf1, buf2 = [], [] + body.each { |part| buf1 << part } + body.each { |part| buf2 << part } + assert_equal buf1.join, buf2.join + assert_equal File.read(__FILE__), buf1.join + end + it 'serves HEAD requests for files in the public directory' do head "/#{F.basename(__FILE__)}" assert ok?