Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #100

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,8 @@ def send_file(path, opts={})
stat = File.stat(path)
last_modified stat.mtime

content_type mime_type(opts[:type]) ||
opts[:type] ||
mime_type(File.extname(path)) ||
content_type opts[:type] ||
File.extname(path) ||
response['Content-Type'] ||
'application/octet-stream'

Expand Down
18 changes: 9 additions & 9 deletions test/static_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class StaticTest < Test::Unit::TestCase
assert not_found?
end

def test_valid_range(http_range, range, path, file)
def assert_valid_range(http_range, range, path, file)
request = Rack::MockRequest.new(@app)
response = request.get("/#{File.basename(path)}", 'HTTP_RANGE' => http_range)

Expand All @@ -113,23 +113,23 @@ def test_valid_range(http_range, range, path, file)
assert length > 9000, "The test file #{path} is too short (#{length} bytes) to run these tests"

[0..0, 42..88, 1234..1234, 100..9000, 0..(length-1), (length-1)..(length-1)].each do |range|
test_valid_range("bytes=#{range.begin}-#{range.end}", range, path, file)
assert_valid_range("bytes=#{range.begin}-#{range.end}", range, path, file)
end

[0, 100, length-100, length-1].each do |start|
test_valid_range("bytes=#{start}-", (start..length-1), path, file)
assert_valid_range("bytes=#{start}-", (start..length-1), path, file)
end

[1, 100, length-100, length-1, length].each do |range_length|
test_valid_range("bytes=-#{range_length}", (length-range_length..length-1), path, file)
assert_valid_range("bytes=-#{range_length}", (length-range_length..length-1), path, file)
end

# Some valid ranges that exceed the length of the file:
test_valid_range("bytes=100-999999", (100..length-1), path, file)
test_valid_range("bytes=100-#{length}", (100..length-1), path, file)
test_valid_range("bytes=-#{length}", (0..length-1), path, file)
test_valid_range("bytes=-#{length+1}", (0..length-1), path, file)
test_valid_range("bytes=-999999", (0..length-1), path, file)
assert_valid_range("bytes=100-999999", (100..length-1), path, file)
assert_valid_range("bytes=100-#{length}", (100..length-1), path, file)
assert_valid_range("bytes=-#{length}", (0..length-1), path, file)
assert_valid_range("bytes=-#{length+1}", (0..length-1), path, file)
assert_valid_range("bytes=-999999", (0..length-1), path, file)
end

it 'correctly ignores syntactically invalid range requests' do
Expand Down