Skip to content

Instantly share code, notes, and snippets.

@skade
Created April 22, 2010 09:12
Show Gist options
  • Save skade/375010 to your computer and use it in GitHub Desktop.
Save skade/375010 to your computer and use it in GitHub Desktop.
diff --git a/padrino-core/lib/padrino-core/application/routing.rb b/padrino-core/lib/padrino-core/application/routing.rb
index a978218..3ea7c25 100644
--- a/padrino-core/lib/padrino-core/application/routing.rb
+++ b/padrino-core/lib/padrino-core/application/routing.rb
@@ -12,6 +12,8 @@ module Padrino
# to the url throughout the application.
#
module Routing
+ CONTENT_TYPE_ALIASES = {:htm => :html}
+
class UnrecognizedException < RuntimeError #:nodoc:
end
@@ -404,7 +406,8 @@ module Padrino
match_format = types.include?(format) || types.include?(:any)
@_content_type =
if mime_type = matching_types.first
- Rack::Mime::MIME_TYPES.find { |k, v| v == matching_types.first }[0].sub(/\./,'').to_sym
+ type = Rack::Mime::MIME_TYPES.find { |k, v| v == matching_types.first }[0].sub(/\./,'').to_sym
+ CONTENT_TYPE_ALIASES[type] || type
else
format
end
diff --git a/padrino-core/test/test_routing.rb b/padrino-core/test/test_routing.rb
index 7f745a0..85c20a9 100644
--- a/padrino-core/test/test_routing.rb
+++ b/padrino-core/test/test_routing.rb
@@ -406,6 +406,20 @@ class TestRouting < Test::Unit::TestCase
get '/bar', {}, { 'HTTP_ACCEPT' => 'application/xml' }
assert_equal 'Bar in html', body
end
+
+ should "set content_type to :html for both empty Accept as well as Accept text/html" do
+ mock_app do
+ provides :html
+
+ get("/foo"){ content_type.to_s }
+ end
+
+ get '/foo', {}, {}
+ assert_equal 'html', body
+
+ get '/foo', {}, { 'HTTP_ACCEPT' => 'text/html' }
+ assert_equal 'html', body
+ end
should 'allows custom route-conditions to be set via route options' do
protector = Module.new {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment