Permalink
Browse files

small refactor

  • Loading branch information...
1 parent 0d1e3c5 commit ebcc43fbcc8d2462cec37fb8c5511d9271393749 @rkh rkh committed Dec 10, 2012
Showing with 6 additions and 13 deletions.
  1. +4 −11 lib/rack/protection/base.rb
  2. +2 −2 spec/protection_spec.rb
@@ -10,7 +10,8 @@ class Base
:reaction => :default_reaction, :logging => true,
:message => 'Forbidden', :encryptor => Digest::SHA1,
:session_key => 'rack.session', :status => 403,
- :allow_empty_referrer => true
+ :allow_empty_referrer => true,
+ :html_types => %w[text/html application/xhtml]
}
attr_reader :app, :options
@@ -98,16 +99,8 @@ def encrypt(value)
alias default_reaction deny
def html?(headers)
- if type = headers.detect { |k,v| k.downcase == 'content-type' }
- case type.last[/^\w+\/\w+/]
- when 'text/html', 'application/xhtml'
- true
- else
- false
- end
- else
- false
- end
+ return false unless header = headers.detect { |k,v| k.downcase == 'content-type' }
+ options[:html_types].include? header.last[/^\w+\/\w+/]
end
end
end
View
@@ -20,12 +20,12 @@
describe "#html?" do
context "given an appropriate content-type header" do
- subject { Rack::Protection::Base.new(nil).html?({'content-type' => "text/html"}) }
+ subject { Rack::Protection::Base.new(nil).html? 'content-type' => "text/html" }
it { should be_true }
end
context "given an inappropriate content-type header" do
- subject { Rack::Protection::Base.new(nil).html?({'content-type' => "image/gif"}) }
+ subject { Rack::Protection::Base.new(nil).html? 'content-type' => "image/gif" }
it { should be_false }
end

0 comments on commit ebcc43f

Please sign in to comment.