Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absurd bespoke MIME type handling should be removed #4

Open
ctrlcctrlv opened this issue Mar 31, 2021 · 0 comments
Open

Absurd bespoke MIME type handling should be removed #4

ctrlcctrlv opened this issue Mar 31, 2021 · 0 comments

Comments

@ctrlcctrlv
Copy link

alacrity/src/WebApp.hs

Lines 96 to 143 in 37aebe4

-- Takes the output data and outputs it with the appropriate content-type
outputResult :: String -> (B.ByteString, Status) -> ActionM ()
outputResult !ext !(!dat, !httpStatus) = outResult httpStatus dat $!
case ext of
".html" -> customOut HTML
".json" -> customOut JSON
".css" -> customOut CSS
".jpg" -> customOut JPG
".gif" -> customOut GIF
".mp4" -> customOut MP4
".ogg" -> customOut OGG
".ico" -> customOut ICO
".svg" -> customOut SVG
".png" -> customOut PNG
".pdf" -> customOut PDF
".jpeg" -> customOut JPEG
".webm" -> customOut WEBM
".js" -> customOut JS
".txt" -> customOut TXT
_ -> customOut Unsupported
{-# INLINABLE outputResult #-}
-- Manages the output content type and binary/text implementations
-- Natively supported file types:
-- txt jpg webm html json gif jpeg php png ico svg css js
-- (defaults to octet-stream for non-supported file types)
customOut :: CustomOut -> BL.ByteString -> ActionM ()
customOut !cout !pFile = do
case cout of
HTML -> setContentType "text/html; charset=utf-8"
JSON -> setContentType "application/json; charset=utf-8"
CSS -> setContentType "text/css; charset=utf-8"
GIF -> setContentType "image/gif"
SVG -> setContentType "image/svg+xml"
ICO -> setContentType "image/x-icon"
JPG -> setContentType "image/jpeg"
MP4 -> setContentType "video/mp4"
OGG -> setContentType "audio/ogg"
PNG -> setContentType "image/png"
PDF -> setContentType "application/pdf"
JPEG -> setContentType "image/jpeg"
WEBM -> setContentType "video/webm"
JS -> setContentType "text/javascript; charset=utf-8"
TXT -> setContentType "text/plain; charset=utf-8"
Unsupported -> setContentType "application/octet-stream"
!r <- raw pFile
return $! r
{-# INLINABLE customOut #-}

A well known file provided by the Apache project for conversion of file extension to MIME type is mime.types.

This file is so useful that on Arch Linux at the very least, it's promoted to the root of /etc, as /etc/mime.types.

Yet, alacritty can only understand a very few MIME types. On startup it should parse the system mime.types and use that as the database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant