Permalink
Browse files

Set headers with Sinatra helpers

Less code!

According to docs, expires sets both `Cache-Control` and `Expires`,
taking just an integer argument:

http://rubydoc.info/gems/sinatra/Sinatra/Helpers#expires-instance_method

`content_type` is a little cleaner too:

http://rubydoc.info/gems/sinatra/Sinatra/Helpers#content_type-instance_method
  • Loading branch information...
1 parent cad580a commit a662a1a02963d095d52a4dcf8543015bb451e5a1 @garethrees garethrees committed with croaky Nov 22, 2012
Showing with 12 additions and 15 deletions.
  1. +1 −1 Gemfile.lock
  2. +10 −13 lib/fistface.rb
  3. +1 −1 spec/fistface_spec.rb
View
@@ -22,7 +22,7 @@ GEM
rspec-mocks (2.6.0)
sinatra (1.2.7)
rack (~> 1.1)
- tilt (< 2.0, >= 1.2.2)
+ tilt (>= 1.2.2, < 2.0)
tilt (1.3.3)
timecop (0.3.5)
View
@@ -6,26 +6,23 @@ module FistFace
def self.registered(app)
app.before do
- one_year_in_seconds = 31536000
-
- headers 'Cache-Control' => "public, max-age=#{one_year_in_seconds}",
- 'Expires' => (Time.now + one_year_in_seconds).httpdate,
- 'Access-Control-Allow-Origin' => '*'
+ expires 31536000, :public
+ headers 'Access-Control-Allow-Origin' => '*'
end
app.get '/:font_face.css' do
- headers['Content-Type'] = 'text/css'
+ content_type 'text/css'
open("#{ENV['S3_URL']}/#{params[:font_face]}.css").read
end
app.get '/:directory/:font_face' do
- headers['Content-Type'] = case params[:font_face]
- when /\.ttf$/ then 'font/truetype'
- when /\.otf$/ then 'font/opentype'
- when /\.woff$/ then 'font/woff'
- when /\.eot$/ then 'application/vnd.ms-fontobject'
- when /\.svg$/ then 'image/svg+xml'
- end
+ content_type case params[:font_face]
+ when /\.ttf$/ then 'font/truetype'
+ when /\.otf$/ then 'font/opentype'
+ when /\.woff$/ then 'font/woff'
+ when /\.eot$/ then 'application/vnd.ms-fontobject'
+ when /\.svg$/ then 'image/svg+xml'
+ end
open("#{ENV['S3_URL']}/#{params[:directory]}/#{params[:font_face]}").read
end
@@ -25,7 +25,7 @@ def app
end
it "is in the CSS Content-Type" do
- last_response.content_type.should == 'text/css'
+ last_response.content_type.should == 'text/css;charset=utf-8'
end
it "wildcards the Access-Control-Allow-Origin header so Firefox can access the file" do

0 comments on commit a662a1a

Please sign in to comment.