Skip to content

Absurd bespoke MIME type handling should be removed #4

@ctrlcctrlv

Description

@ctrlcctrlv

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions