Creating a class to build the default middleware stack.

A lot of logic for building the default middleware stack is currently
kept in Application class, but this can be encapsulated and made more
modular by being moved to its own class. Also refactored a couple of the
helper methods.
Merge pull request #10968 from wangjohn/refactoring_rails_application_class

Creating a class to build the default middleware stack.