Skip to content

Commit 786fb94

Browse files
authored
Merge pull request rails#51545 from etiennebarrie/allow-browser-406
Respond with 406 when a browser is blocked by allow_browser
2 parents af78e7f + 1dc7620 commit 786fb94

File tree

7 files changed

+11
-10
lines changed

7 files changed

+11
-10
lines changed

actionpack/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
* Add `allow_browser` to set minimum browser versions for the application.
1010

11-
A browser that's blocked will by default be served the file in `public/426.html` with a HTTP status code of "426 Upgrade Required".
11+
A browser that's blocked will by default be served the file in `public/406-unsupported-browser.html` with a HTTP status code of "406 Not Acceptable".
1212

1313
```ruby
1414
class ApplicationController < ActionController::Base

actionpack/lib/action_controller/metal/allow_browser.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ module ClassMethods
1313
# versions specified. This means that all other browsers, as well as agents that
1414
# aren't reporting a user-agent header, will be allowed access.
1515
#
16-
# A browser that's blocked will by default be served the file in public/426.html
17-
# with a HTTP status code of "426 Upgrade Required".
16+
# A browser that's blocked will by default be served the file in
17+
# public/406-unsupported-browser.html with a HTTP status code of "406 Not
18+
# Acceptable".
1819
#
1920
# In addition to specifically named browser versions, you can also pass
2021
# `:modern` as the set to restrict support to browsers natively supporting webp
@@ -43,7 +44,7 @@ module ClassMethods
4344
# # In addition to the browsers blocked by ApplicationController, also block Opera below 104 and Chrome below 119 for the show action.
4445
# allow_browser versions: { opera: 104, chrome: 119 }, only: :show
4546
# end
46-
def allow_browser(versions:, block: -> { render file: Rails.root.join("public/426.html"), layout: false, status: :upgrade_required }, **options)
47+
def allow_browser(versions:, block: -> { render file: Rails.root.join("public/406-unsupported-browser.html"), layout: false, status: :not_acceptable }, **options)
4748
before_action -> { allow_browser(versions: versions, block: block) }, **options
4849
end
4950
end

railties/lib/rails/generators/rails/app/app_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ def delete_app_views_if_api_option
495495
def delete_public_files_if_api_option
496496
if options[:api]
497497
remove_file "public/404.html"
498+
remove_file "public/406-unsupported-browser.html"
498499
remove_file "public/422.html"
499-
remove_file "public/426.html"
500500
remove_file "public/500.html"
501501
remove_file "public/icon.png"
502502
remove_file "public/icon.svg"

railties/lib/rails/generators/rails/app/templates/public/426.html renamed to railties/lib/rails/generators/rails/app/templates/public/406-unsupported-browser.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>Your browser is not supported (426)</title>
4+
<title>Your browser is not supported (406)</title>
55
<meta name="viewport" content="width=device-width,initial-scale=1">
66
<style>
77
.rails-default-error-page {
@@ -55,7 +55,7 @@
5555
</head>
5656

5757
<body class="rails-default-error-page">
58-
<!-- This file lives in public/426.html -->
58+
<!-- This file lives in public/406-unsupported-browser.html -->
5959
<div class="dialog">
6060
<div>
6161
<h1>Your browser is not supported.</h1>

railties/test/generators/api_app_generator_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def skipped_files
191191
test/helpers
192192
public/404.html
193193
public/422.html
194-
public/426.html
194+
public/406-unsupported-browser.html
195195
public/500.html
196196
public/icon.png
197197
public/icon.svg

railties/test/generators/app_generator_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
lib/tasks/.keep
7070
log/.keep
7171
public/404.html
72+
public/406-unsupported-browser.html
7273
public/422.html
73-
public/426.html
7474
public/500.html
7575
public/icon.png
7676
public/icon.svg

railties/test/generators/plugin_generator_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
test/dummy/lib/assets/.keep
6262
test/dummy/log/.keep
6363
test/dummy/public/404.html
64+
test/dummy/public/406-unsupported-browser.html
6465
test/dummy/public/422.html
65-
test/dummy/public/426.html
6666
test/dummy/public/500.html
6767
test/dummy/public/icon.png
6868
test/dummy/public/icon.svg

0 commit comments

Comments
 (0)