🧚 A practical web framework for Gleam

Extract mime types handling

+9 -119
+1
gleam.toml
··· 18 18 gleam_stdlib = "~> 0.29" 19 19 mist = "~> 0.13" 20 20 simplifile = "~> 0.1" 21 + marceau = "~> 1.0" 21 22 22 23 [dev-dependencies] 23 24 gleeunit = "~> 0.10"
+6 -4
manifest.toml
··· 4 4 packages = [ 5 5 { name = "exception", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "71F00057D38ADB03BBCCD0E3B07AB2C236BD49DBA7E7611A9DADBD1E26C9F53D" }, 6 6 { name = "gleam_bitwise", version = "1.3.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "E2A46EE42E5E9110DAD67E0F71E7358CBE54D5EC22C526DD48CBBA3223025792" }, 7 - { name = "gleam_crypto", version = "0.4.0", build_tools = ["gleam"], requirements = ["gleam_bitwise", "gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "42429CED0F838B40014E1C017B0495C46C311D08035D2C2D43B749B91A4374F6" }, 7 + { name = "gleam_crypto", version = "0.4.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_bitwise"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "42429CED0F838B40014E1C017B0495C46C311D08035D2C2D43B749B91A4374F6" }, 8 8 { name = "gleam_erlang", version = "0.22.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "367D8B41A7A86809928ED1E7E55BFD0D46D7C4CF473440190F324AFA347109B4" }, 9 9 { name = "gleam_http", version = "3.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "FAE9AE3EB1CA90C2194615D20FFFD1E28B630E84DACA670B28D959B37BCBB02C" }, 10 10 { name = "gleam_json", version = "0.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "C6CC5BEECA525117E97D0905013AB3F8836537455645DDDD10FE31A511B195EF" }, 11 - { name = "gleam_otp", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "ED7381E90636E18F5697FD7956EECCA635A3B65538DC2BE2D91A38E61DCE8903" }, 11 + { name = "gleam_otp", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang"], otp_app = "gleam_otp", source = "hex", outer_checksum = "ED7381E90636E18F5697FD7956EECCA635A3B65538DC2BE2D91A38E61DCE8903" }, 12 12 { name = "gleam_stdlib", version = "0.30.2", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "8D8BF3790AA31176B1E1C0B517DD74C86DA8235CF3389EA02043EE4FD82AE3DC" }, 13 13 { name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" }, 14 - { name = "glisten", version = "0.8.2", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang", "gleam_otp"], otp_app = "glisten", source = "hex", outer_checksum = "364E9B3D4F78308D2EEE5D73E0FB16C686E08516943EFDA501B17177B382907C" }, 15 - { name = "mist", version = "0.13.2", build_tools = ["gleam"], requirements = ["glisten", "gleam_erlang", "gleam_http", "gleam_stdlib", "gleam_otp"], otp_app = "mist", source = "hex", outer_checksum = "51C385C58A78A2013A30F92705814560AD9A2B8EC3ECBA94C620F22D3ACB50BC" }, 14 + { name = "glisten", version = "0.8.2", build_tools = ["gleam"], requirements = ["gleam_otp", "gleam_erlang", "gleam_stdlib"], otp_app = "glisten", source = "hex", outer_checksum = "364E9B3D4F78308D2EEE5D73E0FB16C686E08516943EFDA501B17177B382907C" }, 15 + { name = "marceau", version = "1.0.0", build_tools = ["gleam"], requirements = [], otp_app = "marceau", source = "hex", outer_checksum = "B2E34F201E4B22BBB54C9FCCF0444B8079D9C387A31FD7F12A3F65E0C5307624" }, 16 + { name = "mist", version = "0.13.2", build_tools = ["gleam"], requirements = ["glisten", "gleam_http", "gleam_otp", "gleam_stdlib", "gleam_erlang"], otp_app = "mist", source = "hex", outer_checksum = "51C385C58A78A2013A30F92705814560AD9A2B8EC3ECBA94C620F22D3ACB50BC" }, 16 17 { name = "simplifile", version = "0.1.10", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "263B7C7F4B29263555DEA2D30BA918425A27120CDD1E1352744EAB4D56CE01CE" }, 17 18 { name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" }, 18 19 ] ··· 25 26 gleam_json = { version = "~> 0.6" } 26 27 gleam_stdlib = { version = "~> 0.29" } 27 28 gleeunit = { version = "~> 0.10" } 29 + marceau = { version = "~> 1.0" } 28 30 mist = { version = "~> 0.13" } 29 31 simplifile = { version = "~> 0.1" }
+2 -115
src/wisp.gleam
··· 18 18 import gleam/string 19 19 import gleam/string_builder.{StringBuilder} 20 20 import gleam/uri 21 + import marceau 21 22 import mist 22 23 import simplifile 23 24 import wisp/internal/logger ··· 1243 1244 } 1244 1245 1245 1246 // 1246 - // MIME types 1247 - // 1248 - 1249 - // TODO: move to another package 1250 - fn extension_to_mime_type(extension: String) -> String { 1251 - case extension { 1252 - "7z" -> "application/x-7z-compressed" 1253 - "aac" -> "audio/aac" 1254 - "abw" -> "application/x-abiword" 1255 - "ai" -> "application/postscript" 1256 - "arc" -> "application/x-freearc" 1257 - "asice" -> "application/vnd.etsi.asic-e+zip" 1258 - "asics" -> "application/vnd.etsi.asic-s+zip" 1259 - "atom" -> "application/atom+xml" 1260 - "avi" -> "video/x-msvideo" 1261 - "avif" -> "image/avif" 1262 - "azw" -> "application/vnd.amazon.ebook" 1263 - "bin" -> "application/octet-stream" 1264 - "bmp" -> "image/bmp" 1265 - "bz" -> "application/x-bzip" 1266 - "bz2" -> "application/x-bzip2" 1267 - "cda" -> "application/x-cdf" 1268 - "csh" -> "application/x-csh" 1269 - "css" -> "text/css" 1270 - "csv" -> "text/csv" 1271 - "doc" -> "application/msword" 1272 - "docx" -> 1273 - "application/vnd.openxmlformats-officedocument.wordprocessingml.document" 1274 - "eot" -> "application/vnd.ms-fontobject" 1275 - "eps" -> "application/postscript" 1276 - "epub" -> "application/epub+zip" 1277 - "gif" -> "image/gif" 1278 - "gz" -> "application/gzip" 1279 - "heic" -> "image/heic" 1280 - "heif" -> "image/heif" 1281 - "htm" -> "text/html" 1282 - "html" -> "text/html" 1283 - "ico" -> "image/vnd.microsoft.icon" 1284 - "ics" -> "text/calendar" 1285 - "jar" -> "application/java-archive" 1286 - "jpeg" -> "image/jpeg" 1287 - "jpg" -> "image/jpeg" 1288 - "js" -> "text/javascript" 1289 - "json" -> "application/json" 1290 - "json-api" -> "application/vnd.api+json" 1291 - "json-patch" -> "application/json-patch+json" 1292 - "jsonld" -> "application/ld+json" 1293 - "jxl" -> "image/jxl" 1294 - "markdown" -> "text/markdown" 1295 - "md" -> "text/markdown" 1296 - "mdb" -> "application/x-msaccess" 1297 - "mid" -> "audio/midi" 1298 - "midi" -> "audio/midi" 1299 - "mjs" -> "text/javascript" 1300 - "mov" -> "video/quicktime" 1301 - "mp3" -> "audio/mpeg" 1302 - "mp4" -> "video/mp4" 1303 - "mpeg" -> "video/mpeg" 1304 - "mpg" -> "video/mpeg" 1305 - "mpkg" -> "application/vnd.apple.installer+xml" 1306 - "odp" -> "application/vnd.oasis.opendocument.presentation" 1307 - "ods" -> "application/vnd.oasis.opendocument.spreadsheet" 1308 - "odt" -> "application/vnd.oasis.opendocument.text" 1309 - "oga" -> "audio/ogg" 1310 - "ogv" -> "video/ogg" 1311 - "ogx" -> "application/ogg" 1312 - "opus" -> "audio/opus" 1313 - "otf" -> "font/otf" 1314 - "pdf" -> "application/pdf" 1315 - "php" -> "application/x-httpd-php" 1316 - "png" -> "image/png" 1317 - "ppt" -> "application/vnd.ms-powerpoint" 1318 - "pptx" -> 1319 - "application/vnd.openxmlformats-officedocument.presentationml.presentation" 1320 - "ps" -> "application/postscript" 1321 - "psd" -> "image/vnd.adobe.photoshop" 1322 - "rar" -> "application/vnd.rar" 1323 - "rss" -> "application/rss+xml" 1324 - "rtf" -> "application/rtf" 1325 - "sce" -> "application/vnd.etsi.asic-e+zip" 1326 - "scs" -> "application/vnd.etsi.asic-s+zip" 1327 - "sh" -> "application/x-sh" 1328 - "svg" -> "image/svg+xml" 1329 - "svgz" -> "image/svg+xml" 1330 - "swf" -> "application/x-shockwave-flash" 1331 - "tar" -> "application/x-tar" 1332 - "text" -> "text/plain" 1333 - "tif" -> "image/tiff" 1334 - "tiff" -> "image/tiff" 1335 - "ts" -> "video/mp2t" 1336 - "ttf" -> "font/ttf" 1337 - "txt" -> "text/plain" 1338 - "vsd" -> "application/vnd.visio" 1339 - "wasm" -> "application/wasm" 1340 - "wav" -> "audio/wav" 1341 - "weba" -> "audio/webm" 1342 - "webm" -> "video/webm" 1343 - "webmanifest" -> "application/manifest+json" 1344 - "webp" -> "image/webp" 1345 - "wmv" -> "video/x-ms-wmv" 1346 - "woff" -> "font/woff" 1347 - "woff2" -> "font/woff2" 1348 - "xhtml" -> "application/xhtml+xml" 1349 - "xls" -> "application/vnd.ms-excel" 1350 - "xlsx" -> 1351 - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" 1352 - "xml" -> "application/xml" 1353 - "xul" -> "application/vnd.mozilla.xul+xml" 1354 - "zip" -> "application/zip" 1355 - _ -> "application/octet-stream" 1356 - } 1357 - } 1358 - 1359 - // 1360 1247 // Middleware 1361 1248 // 1362 1249 ··· 1489 1376 |> string.split(on: ".") 1490 1377 |> list.last 1491 1378 |> result.unwrap("") 1492 - |> extension_to_mime_type 1379 + |> marceau.extension_to_mime_type 1493 1380 1494 1381 case simplifile.is_file(path) { 1495 1382 False -> handler()