Handling missing mime types gracefully #534
Labels
feature
Code based project improvement
good first issue
an issue suitable to start contributing to the project
If a key isn't present in the mime_types map, an exception is thrown. This is because mime_types.at() is used at, e.g.,
Crow/include/crow/http_response.h
Line 104 in c0bfaa7
I propose that the resolution is to search for the provided mime_type within the map using
mime_types.find
. If it is not found, a warning should be logged, but the content should still be delivered using the following logic:Does the provided type look like a MIME type already? I.e. is it one of the IANA-registered types (application, audio, example, font, image, model, text, video), followed by a slash, followed by text? If so, send that verbatim.
Otherwise send text/plain.
Although this approach isn't quite as lightweight as simply sending text/plain, there are some benefits:
text/csv
without modifying the mime types map.text/plain;charset=UTF-8
)The text was updated successfully, but these errors were encountered: