backport https://github.com/rails/rails/commit/000edbbbaceedc2f6df2b039d44de6e7cb7118e7

Current actionpack test status:

3603 tests, 16198 assertions, 4 failures, 0 errors, 0 skips