Backport https://github.com/rack/rack/pull/737

This doesn't include the #respond_to? changes, because they were reverted in https://github.com/rack/rack/pull/739