denoland/std

Clean up `media_types` module

Closed this issue · 1 comments

kt3k commented

typeByExtention API looks redundant as it's covered by contentType. I think we should deprecate it before stabilizing it.

part of #3489

I raised concerns about this in the discord room... https://discord.com/channels/684898665143206084/775393009981849600/1178747037072756867

I use typeByExtension to resolve extensions to simple media types for use in a media type matching function here.

This is an example of how that function is used, here.

In the example linked above, it matches by URL pattern (/hello{.:ext}?), then by method (GET), then by the preferred media type (either text/plain, text/html, or application/json) which is determined by the Accept header (if /hello is called), or explicitly by extension (if /hello.txt, /hello.html, or /hello.json is called). This makes it easy to automatically supply the correct content type, and to also manually view a particular content type directly in the browser or elsewhere.

contentType is not suitable as it adds additional parameters (eg. charset) to the result, I'd have to parse this to extract the simple media type, which is a pain, considering contentType uses typeByExtension internally anyway.