Browse files

Merge pull request #84 from fgrehm/master

Fix http accept type sorting
  • Loading branch information...
2 parents 492260c + 6e0d856 commit cc2b1859464c1865a3cba19e2e03775c9d8c6c93 @sam committed Jun 25, 2012
Showing with 4 additions and 2 deletions.
  1. +3 −1 lib/harbor/request.rb
  2. +1 −1 test/request_test.rb
View
4 lib/harbor/request.rb
@@ -137,7 +137,9 @@ def path
def accept
@accept ||= begin
entries = @env['HTTP_ACCEPT'].to_s.split(',')
- entries.map { |e| accept_entry(e) }.sort_by(&:last).map(&:first)
+ entries.map! { |e| accept_entry(e) }
+ entries.sort_by! { |e| [e.last, entries.index(e)] }
+ entries.map(&:first)
end
end
View
2 test/request_test.rb
@@ -27,7 +27,7 @@ def test_params_fetch
def test_extracts_accept_types_preserving_quality_order
request = get("/", { 'HTTP_ACCEPT' => 'text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c, */*; q=0.1' })
- expected_accept = ['text/x-c', 'text/html', 'text/x-dvi', 'text/plain', '*/*']
+ expected_accept = ['text/html', 'text/x-c', 'text/x-dvi', 'text/plain', '*/*']
assert_equal expected_accept, request.accept
end

0 comments on commit cc2b185

Please sign in to comment.