{"action":"created","comment":{"url":"https://api.github.com/repos/rails/web-console/pulls/comments/35625517","id":35625517,"diff_hunk":"@@ -58,6 +59,25 @@ def call(env)\n \n     private\n \n+      # Returns whether the response is from an acceptable content type.\n+      #\n+      # We can render a console for HTML and TEXT by default.\n+      def acceptable_response_content_type?(headers, env)","path":"lib/web_console/middleware.rb","position":27,"original_position":27,"commit_id":"61a8db994f9440e44ab8102b2e9ddadda5333527","original_commit_id":"61a8db994f9440e44ab8102b2e9ddadda5333527","user":{"login":"gsamokovarov","id":604618,"avatar_url":"https://avatars.githubusercontent.com/u/604618?v=3","gravatar_id":"","url":"https://api.github.com/users/gsamokovarov","html_url":"https://github.com/gsamokovarov","followers_url":"https://api.github.com/users/gsamokovarov/followers","following_url":"https://api.github.com/users/gsamokovarov/following{/other_user}","gists_url":"https://api.github.com/users/gsamokovarov/gists{/gist_id}","starred_url":"https://api.github.com/users/gsamokovarov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gsamokovarov/subscriptions","organizations_url":"https://api.github.com/users/gsamokovarov/orgs","repos_url":"https://api.github.com/users/gsamokovarov/repos","events_url":"https://api.github.com/users/gsamokovarov/events{/privacy}","received_events_url":"https://api.github.com/users/gsamokovarov/received_events","type":"User","site_admin":false},"body":"I get it now. Let's try that. :+1: ","created_at":"2015-07-28T08:39:12Z","updated_at":"2015-07-28T08:39:12Z","html_url":"https://github.com/rails/web-console/pull/152#discussion_r35625517","pull_request_url":"https://api.github.com/repos/rails/web-console/pulls/152","_links":{"self":{"href":"https://api.github.com/repos/rails/web-console/pulls/comments/35625517"},"html":{"href":"https://github.com/rails/web-console/pull/152#discussion_r35625517"},"pull_request":{"href":"https://api.github.com/repos/rails/web-console/pulls/152"}}},"pull_request":{"url":"https://api.github.com/repos/rails/web-console/pulls/152","id":40844881,"html_url":"https://github.com/rails/web-console/pull/152","diff_url":"https://github.com/rails/web-console/pull/152.diff","patch_url":"https://github.com/rails/web-console/pull/152.patch","issue_url":"https://api.github.com/repos/rails/web-console/issues/152","number":152,"state":"open","locked":false,"title":"Rely on response content type to render or not the web console","user":{"login":"jmbejar","id":487140,"avatar_url":"https://avatars.githubusercontent.com/u/487140?v=3","gravatar_id":"","url":"https://api.github.com/users/jmbejar","html_url":"https://github.com/jmbejar","followers_url":"https://api.github.com/users/jmbejar/followers","following_url":"https://api.github.com/users/jmbejar/following{/other_user}","gists_url":"https://api.github.com/users/jmbejar/gists{/gist_id}","starred_url":"https://api.github.com/users/jmbejar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmbejar/subscriptions","organizations_url":"https://api.github.com/users/jmbejar/orgs","repos_url":"https://api.github.com/users/jmbejar/repos","events_url":"https://api.github.com/users/jmbejar/events{/privacy}","received_events_url":"https://api.github.com/users/jmbejar/received_events","type":"User","site_admin":false},"body":"This PR goal is to improve the logic behind the decision of render or not the web console in the response when some error happens in a Rails app.\r\n\r\nWe found this issue testing the Rails API-only feature that was recently merged into Rails' master. For instance, we found that the web console code was being appended to JSON responses.\r\n\r\nHowever, it is not only a problem with API-only apps. This issue occurs because `Rails` and `web-console` were using a different logic to calculate the response format (in other words, the response's content type). While `Rails` defines the response format based on the extension in the URL and the Accept headers in the request, `web-console` was relying on the request `Content-Type` header.\r\nEven worse, the response type in Rails can still be overrided by `ActionDispatch::DebugExceptions` to return a response with an HTML response, even if the client requested a different format.\r\n\r\nIn any case, the request `Content-Type` header should not be used to deduce the response content type. Rails code is not doing that. According [RFC 2616 section 7.2.1](http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.2.1), this header indicates the format of the data in the request body.\r\n\r\nIn Rails, [this code is the responsible for setting the response content type](https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/mime_negotiation.rb#L50-L72).\r\n\r\nThe approach in this PR is to grab the response content type from the headers that are being passed through the middleware chain. When `web-console` middleware is processed, Rails already returned the response content type so it's easy to check if the response is a html page (where the console can be appended) or something different.","created_at":"2015-07-25T23:13:13Z","updated_at":"2015-07-28T08:39:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e46e6b73749865932d0f4deb60d309d4bf5674de","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rails/web-console/pulls/152/commits","review_comments_url":"https://api.github.com/repos/rails/web-console/pulls/152/comments","review_comment_url":"https://api.github.com/repos/rails/web-console/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rails/web-console/issues/152/comments","statuses_url":"https://api.github.com/repos/rails/web-console/statuses/61a8db994f9440e44ab8102b2e9ddadda5333527","head":{"label":"jmbejar:rely-on-response-content-type-to-render-console","ref":"rely-on-response-content-type-to-render-console","sha":"61a8db994f9440e44ab8102b2e9ddadda5333527","user":{"login":"jmbejar","id":487140,"avatar_url":"https://avatars.githubusercontent.com/u/487140?v=3","gravatar_id":"","url":"https://api.github.com/users/jmbejar","html_url":"https://github.com/jmbejar","followers_url":"https://api.github.com/users/jmbejar/followers","following_url":"https://api.github.com/users/jmbejar/following{/other_user}","gists_url":"https://api.github.com/users/jmbejar/gists{/gist_id}","starred_url":"https://api.github.com/users/jmbejar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmbejar/subscriptions","organizations_url":"https://api.github.com/users/jmbejar/orgs","repos_url":"https://api.github.com/users/jmbejar/repos","events_url":"https://api.github.com/users/jmbejar/events{/privacy}","received_events_url":"https://api.github.com/users/jmbejar/received_events","type":"User","site_admin":false},"repo":{"id":39686655,"name":"web-console","full_name":"jmbejar/web-console","owner":{"login":"jmbejar","id":487140,"avatar_url":"https://avatars.githubusercontent.com/u/487140?v=3","gravatar_id":"","url":"https://api.github.com/users/jmbejar","html_url":"https://github.com/jmbejar","followers_url":"https://api.github.com/users/jmbejar/followers","following_url":"https://api.github.com/users/jmbejar/following{/other_user}","gists_url":"https://api.github.com/users/jmbejar/gists{/gist_id}","starred_url":"https://api.github.com/users/jmbejar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmbejar/subscriptions","organizations_url":"https://api.github.com/users/jmbejar/orgs","repos_url":"https://api.github.com/users/jmbejar/repos","events_url":"https://api.github.com/users/jmbejar/events{/privacy}","received_events_url":"https://api.github.com/users/jmbejar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jmbejar/web-console","description":"Rails Console on the Browser.","fork":true,"url":"https://api.github.com/repos/jmbejar/web-console","forks_url":"https://api.github.com/repos/jmbejar/web-console/forks","keys_url":"https://api.github.com/repos/jmbejar/web-console/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jmbejar/web-console/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jmbejar/web-console/teams","hooks_url":"https://api.github.com/repos/jmbejar/web-console/hooks","issue_events_url":"https://api.github.com/repos/jmbejar/web-console/issues/events{/number}","events_url":"https://api.github.com/repos/jmbejar/web-console/events","assignees_url":"https://api.github.com/repos/jmbejar/web-console/assignees{/user}","branches_url":"https://api.github.com/repos/jmbejar/web-console/branches{/branch}","tags_url":"https://api.github.com/repos/jmbejar/web-console/tags","blobs_url":"https://api.github.com/repos/jmbejar/web-console/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jmbejar/web-console/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jmbejar/web-console/git/refs{/sha}","trees_url":"https://api.github.com/repos/jmbejar/web-console/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jmbejar/web-console/statuses/{sha}","languages_url":"https://api.github.com/repos/jmbejar/web-console/languages","stargazers_url":"https://api.github.com/repos/jmbejar/web-console/stargazers","contributors_url":"https://api.github.com/repos/jmbejar/web-console/contributors","subscribers_url":"https://api.github.com/repos/jmbejar/web-console/subscribers","subscription_url":"https://api.github.com/repos/jmbejar/web-console/subscription","commits_url":"https://api.github.com/repos/jmbejar/web-console/commits{/sha}","git_commits_url":"https://api.github.com/repos/jmbejar/web-console/git/commits{/sha}","comments_url":"https://api.github.com/repos/jmbejar/web-console/comments{/number}","issue_comment_url":"https://api.github.com/repos/jmbejar/web-console/issues/comments{/number}","contents_url":"https://api.github.com/repos/jmbejar/web-console/contents/{+path}","compare_url":"https://api.github.com/repos/jmbejar/web-console/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jmbejar/web-console/merges","archive_url":"https://api.github.com/repos/jmbejar/web-console/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jmbejar/web-console/downloads","issues_url":"https://api.github.com/repos/jmbejar/web-console/issues{/number}","pulls_url":"https://api.github.com/repos/jmbejar/web-console/pulls{/number}","milestones_url":"https://api.github.com/repos/jmbejar/web-console/milestones{/number}","notifications_url":"https://api.github.com/repos/jmbejar/web-console/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jmbejar/web-console/labels{/name}","releases_url":"https://api.github.com/repos/jmbejar/web-console/releases{/id}","created_at":"2015-07-25T13:35:21Z","updated_at":"2015-07-25T13:35:21Z","pushed_at":"2015-07-25T23:13:41Z","git_url":"git://github.com/jmbejar/web-console.git","ssh_url":"git@github.com:jmbejar/web-console.git","clone_url":"https://github.com/jmbejar/web-console.git","svn_url":"https://github.com/jmbejar/web-console","homepage":"","size":827,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rails:master","ref":"master","sha":"6b70de4694a73fce43b2016606bc5fa431cce85b","user":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"repo":{"id":12496351,"name":"web-console","full_name":"rails/web-console","owner":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails/web-console","description":"Rails Console on the Browser.","fork":true,"url":"https://api.github.com/repos/rails/web-console","forks_url":"https://api.github.com/repos/rails/web-console/forks","keys_url":"https://api.github.com/repos/rails/web-console/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails/web-console/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails/web-console/teams","hooks_url":"https://api.github.com/repos/rails/web-console/hooks","issue_events_url":"https://api.github.com/repos/rails/web-console/issues/events{/number}","events_url":"https://api.github.com/repos/rails/web-console/events","assignees_url":"https://api.github.com/repos/rails/web-console/assignees{/user}","branches_url":"https://api.github.com/repos/rails/web-console/branches{/branch}","tags_url":"https://api.github.com/repos/rails/web-console/tags","blobs_url":"https://api.github.com/repos/rails/web-console/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails/web-console/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails/web-console/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails/web-console/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails/web-console/statuses/{sha}","languages_url":"https://api.github.com/repos/rails/web-console/languages","stargazers_url":"https://api.github.com/repos/rails/web-console/stargazers","contributors_url":"https://api.github.com/repos/rails/web-console/contributors","subscribers_url":"https://api.github.com/repos/rails/web-console/subscribers","subscription_url":"https://api.github.com/repos/rails/web-console/subscription","commits_url":"https://api.github.com/repos/rails/web-console/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails/web-console/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails/web-console/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails/web-console/issues/comments{/number}","contents_url":"https://api.github.com/repos/rails/web-console/contents/{+path}","compare_url":"https://api.github.com/repos/rails/web-console/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails/web-console/merges","archive_url":"https://api.github.com/repos/rails/web-console/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails/web-console/downloads","issues_url":"https://api.github.com/repos/rails/web-console/issues{/number}","pulls_url":"https://api.github.com/repos/rails/web-console/pulls{/number}","milestones_url":"https://api.github.com/repos/rails/web-console/milestones{/number}","notifications_url":"https://api.github.com/repos/rails/web-console/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails/web-console/labels{/name}","releases_url":"https://api.github.com/repos/rails/web-console/releases{/id}","created_at":"2013-08-30T21:57:37Z","updated_at":"2015-07-24T11:41:58Z","pushed_at":"2015-07-28T08:11:22Z","git_url":"git://github.com/rails/web-console.git","ssh_url":"git@github.com:rails/web-console.git","clone_url":"https://github.com/rails/web-console.git","svn_url":"https://github.com/rails/web-console","homepage":"","size":2376,"stargazers_count":825,"watchers_count":825,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":73,"mirror_url":null,"open_issues_count":13,"forks":73,"open_issues":13,"watchers":825,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/web-console/pulls/152"},"html":{"href":"https://github.com/rails/web-console/pull/152"},"issue":{"href":"https://api.github.com/repos/rails/web-console/issues/152"},"comments":{"href":"https://api.github.com/repos/rails/web-console/issues/152/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/web-console/pulls/152/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/web-console/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rails/web-console/pulls/152/commits"},"statuses":{"href":"https://api.github.com/repos/rails/web-console/statuses/61a8db994f9440e44ab8102b2e9ddadda5333527"}}}}