Backport mime-type parsing fixes

https://github.com/rails/rails/pull/4918