Backport mime-type parsing fixes

https://github.com/rails/rails/pull/4918
Merge pull request #41 from square/mime-type-fixes-backport

Backport mime-type parsing fixes