Page MenuHomePhabricator

MimeAnalyser: Support mapping Content-Type to mime type and/or file extension
Open, Needs TriagePublic

Description

In T252909, a call to $mimeAnalyzer->getExtensionsForType( $contentType ) caused issues when given a Content-Type header. While these headers are often identical to a valid mime type, they can also contain additional segments such as ; charset=utf-8 etc.

The logic for stripping or extracting that should not be spread around different code bases in the form of an ad-hoc regex but rather be centralised in some way.

Perhaps a method on MimeAnalyser makes sense for this, either by magically stripping it from getExtensionsForType parameters, or by a variant of that method more explicitly for HTTP purposes, e.g. getExtensionsFromHttpContentType or some such.

Another way would be to split these concerns and e.g. add a method somewhere in the the wikimedia/http component instead, and require consumers to call both methods, e.g. MimeAnalyser->getExtensionsForType( Wikimedia\Http::getMimeFromContentType( … ) ); or some such.

Event Timeline

Change 596736 had a related patch set uploaded (by Krinkle; owner: Reedy):
[mediawiki/extensions/GWToolset@master] Strip charset from Content-Type before parsing as mime type

https://gerrit.wikimedia.org/r/596736

Change 596736 merged by jenkins-bot:
[mediawiki/extensions/GWToolset@master] Strip charset from Content-Type before parsing as mime type

https://gerrit.wikimedia.org/r/596736