提交 3bccd123 编写于 作者: G Guillermo Iguaran

Remove BestStandardsSupport middleware

上级 88e4ec6e
......@@ -47,7 +47,6 @@ class IllegalStateError < StandardError
autoload_under 'middleware' do
autoload :RequestId
autoload :BestStandardsSupport
autoload :Callbacks
autoload :Cookies
autoload :DebugExceptions
......
module ActionDispatch
class BestStandardsSupport
def initialize(app, type = true)
@app = app
@header = case type
when true
"IE=Edge,chrome=1"
when :builtin
"IE=Edge"
when false
nil
end
end
def call(env)
status, headers, body = @app.call(env)
if headers["X-UA-Compatible"] && @header
unless headers["X-UA-Compatible"][@header]
headers["X-UA-Compatible"] << "," << @header.to_s
end
else
headers["X-UA-Compatible"] = @header
end
[status, headers, body]
end
end
end
......@@ -6,7 +6,6 @@ class Railtie < Rails::Railtie # :nodoc:
config.action_dispatch.x_sendfile_header = nil
config.action_dispatch.ip_spoofing_check = true
config.action_dispatch.show_exceptions = true
config.action_dispatch.best_standards_support = true
config.action_dispatch.tld_length = 1
config.action_dispatch.ignore_accept_header = false
config.action_dispatch.rescue_templates = { }
......
require 'abstract_unit'
class BestStandardsSupportTest < ActiveSupport::TestCase
def test_with_best_standards_support
_, headers, _ = app(true, {}).call({})
assert_equal "IE=Edge,chrome=1", headers["X-UA-Compatible"]
end
def test_with_builtin_best_standards_support
_, headers, _ = app(:builtin, {}).call({})
assert_equal "IE=Edge", headers["X-UA-Compatible"]
end
def test_without_best_standards_support
_, headers, _ = app(false, {}).call({})
assert_equal nil, headers["X-UA-Compatible"]
end
def test_appends_to_app_headers_without_duplication_after_multiple_requests
app_headers = { "X-UA-Compatible" => "requiresActiveX=true" }
_, headers, _ = app(true, app_headers).call({})
_, headers, _ = app(true, app_headers).call({})
expects = "requiresActiveX=true,IE=Edge,chrome=1"
assert_equal expects, headers["X-UA-Compatible"]
end
private
def app(type, headers)
app = proc { [200, headers, "response"] }
ActionDispatch::BestStandardsSupport.new(app, type)
end
end
......@@ -365,10 +365,6 @@ def default_middleware_stack #:nodoc:
middleware.use ::Rack::Head
middleware.use ::Rack::ConditionalGet
middleware.use ::Rack::ETag, "no-cache"
if config.action_dispatch.best_standards_support
middleware.use ::ActionDispatch::BestStandardsSupport, config.action_dispatch.best_standards_support
end
end
end
......
......@@ -27,11 +27,11 @@ module Configuration
#
# Middlewares can also be completely swapped out and replaced with others:
#
# config.middleware.swap ActionDispatch::BestStandardsSupport, Magical::Unicorns
# config.middleware.swap ActionDispatch::Flash, Magical::Unicorns
#
# And finally they can also be removed from the stack completely:
#
# config.middleware.delete ActionDispatch::BestStandardsSupport
# config.middleware.delete ActionDispatch::Flash
#
class MiddlewareStackProxy
def initialize
......
......@@ -19,9 +19,6 @@
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers.
config.action_dispatch.best_standards_support = :builtin
<%- unless options.skip_active_record? -%>
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL).
......
require 'isolation/abstract_unit'
module ApplicationTests
class BestPracticesTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
def setup
build_app
boot_rails
require 'rack/test'
extend Rack::Test::Methods
simple_controller
end
def teardown
teardown_app
end
test "simple controller in production mode returns best standards" do
get '/foo'
assert_equal "IE=Edge,chrome=1", last_response.headers["X-UA-Compatible"]
end
test "simple controller in development mode leaves out Chrome" do
app("development")
get "/foo"
assert_equal "IE=Edge", last_response.headers["X-UA-Compatible"]
end
end
end
......@@ -45,8 +45,7 @@ def app
"ActionDispatch::ParamsParser",
"Rack::Head",
"Rack::ConditionalGet",
"Rack::ETag",
"ActionDispatch::BestStandardsSupport"
"Rack::ETag"
], middleware
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册