Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Lighthouse/5277: Empty HTTP_ACCEPT means the clients accept all media types #101

Closed
wants to merge 2 commits into from

3 participants

@josevalim
Owner

The patch looks almost good! I would just set a default accept header in the accepts method and not in formats. And could I ask you to send the patches to LH instead if we have an open ticket? Otherwise the discussion is broken in two different places. Thanks!

@josevalim
Owner

Ugh, it seems github lost our comments. :)

So, can you please send a new pull request with all the commits that need to be included? Thanks a lot :)

@franckverrot

Eheh no prob: #104

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 13, 2010
  1. @egh @franckverrot

    Failing test for empty accept header [#5277]

    egh authored franckverrot committed
  2. @franckverrot

    Implemented fix for LH#5277: Empty (or missing) HTTP_ACCEPT header me…

    franckverrot authored
    …ans the client accepts all the media types
This page is out of date. Refresh to see the latest.
View
2  actionpack/lib/action_dispatch/http/mime_negotiation.rb
@@ -43,7 +43,7 @@ def format(view_path = [])
end
def formats
- accept = @env['HTTP_ACCEPT']
+ accept = (@env['HTTP_ACCEPT'] ||= '*/*')
@env["action_dispatch.request.formats"] ||=
if parameters[:format]
View
2  actionpack/test/controller/log_subscriber_test.rb
@@ -65,7 +65,7 @@ def test_start_processing
get :show
wait
assert_equal 2, logs.size
- assert_equal "Processing by Another::LogSubscribersController#show as HTML", logs.first
+ assert_equal "Processing by Another::LogSubscribersController#show as */*", logs.first
end
def test_process_action
View
5 actionpack/test/controller/new_base/content_negotiation_test.rb
@@ -14,5 +14,10 @@ class TestContentNegotiation < Rack::TestCase
get "/content_negotiation/basic/hello", {}, "HTTP_ACCEPT" => "*/*"
assert_body "Hello world */*!"
end
+
+ test "An empty accept header will return HTML" do
+ get "/content_negotiation/basic/hello", {}, "HTTP_ACCEPT" => nil
+ assert_body "Hello world */*!"
+ end
end
end
View
3  actionpack/test/dispatch/request_test.rb
@@ -403,7 +403,8 @@ class RequestTest < ActiveSupport::TestCase
assert_equal [ Mime::HTML ], request.formats
request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8',
- 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest"
+ 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest",
+ 'HTTP_ACCEPT' => 'application/xml'
request.expects(:parameters).at_least_once.returns({})
assert_equal with_set(Mime::XML), request.formats
Something went wrong with that request. Please try again.