Permalink
Browse files

Return 406 when all variants are not acceptable

  • Loading branch information...
1 parent 40337d3 commit 9c14fc38d1c562d5ec86a1ff78e647b933830ae0 @dkubb committed Oct 18, 2009
Showing with 14 additions and 7 deletions.
  1. +3 −3 lib/rack/conneg/negotiator.rb
  2. +11 −2 lib/rack/conneg/path.rb
  3. +0 −2 spec/rack/conneg/static_spec.rb
@@ -47,7 +47,7 @@ def initialize(app, env)
#
# @api private
def pass?
- not @path.variants?
+ not @path.exist? ? @path.mime_type.nil? : @path.variants?
end
# The response from the next Rack app
@@ -70,8 +70,8 @@ def pass(env = @request.env)
#
# @api private
def call
- variant = select_variant
- response = variant ? serve_path(variant) : NOT_ACCEPTABLE
+ path = select_variant
+ response = path && path.mime_type ? serve_path(path) : NOT_ACCEPTABLE
self.class.append_vary_header(response[1], 'Accept')
response
end
View
@@ -3,7 +3,6 @@
module Rack
class Conneg
class Path
- EXTENSION_REGEXP = Regexp.union(*Mime::MIME_TYPES.keys.map { |ext| ext[1..-1] }).freeze
# Return the request path
#
@@ -40,6 +39,16 @@ def mime_type
Mime.mime_type(extname, nil)
end
+ # Test if the request path exists
+ #
+ # @return [Boolean]
+ # true if the requested path exists
+ #
+ # @api private
+ def exist?
+ @path.exist?
+ end
+
# Test if there are variants for the request path
#
# @return [Boolean]
@@ -129,7 +138,7 @@ def variant?(other)
#
# @api private
def pattern
- @pattern ||= /\A#{Regexp.escape(path_info)}\.#{EXTENSION_REGEXP}\z/.freeze
+ @pattern ||= /\A#{Regexp.escape(path_info)}\.[a-z\d]+\z/.freeze
end
# Normalize the request path info
@@ -128,8 +128,6 @@ def create_directory(path)
describe 'GET path for file with unknown media type' do
before do
- pending
-
create_file(@file = 'index.unknown')
request "/#{@file}"

0 comments on commit 9c14fc3

Please sign in to comment.