fvsch / servitsy

Small, local HTTP server for static files
MIT License
3 stars 0 forks source link

feat: get content-type from file bytes #18

Closed fvsch closed 1 month ago

fvsch commented 1 month ago

Problem: sending a content-type: application/octet-stream header for every file without a known extension often triggers a download of the file for a top-level navigation. Oftentimes those files are simple text files and could be served with a text/plain content type instead.

This PR implements the “7.2. Sniffing a mislabeled binary resource” algorithm from the MIME Sniffing Standard to try and detect if a file is a text or binary file.