Fix: serve_resource/serve_folder ignore mimetypes and fallback_mimetype parameters
httputils._serve_traversable looked up the Content-Type in the
module-level MIMETYPES/FALLBACK_MIMETYPE constants instead of the
mimetypes/fallback_mimetype parameters that serve_resource() and
serve_folder() accept and pass through. The parameters exist since the
helper was extracted for use by web plugins (33fcda7c, "Extract
httputils.serve_folder"), and the sibling parameters path_prefix and
index_file are honored, but a custom web plugin passing its own
mimetype mapping (e.g. to serve .json, .ico or .mjs files with a
correct Content-Type) silently got the built-in mapping and
application/octet-stream fallback instead.
Use the parameters for the lookup. No behavior change for the built-in
web module, which relies on the defaults.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -209,8 +209,8 @@ def _serve_traversable(
|
||||
traversable = traversable.joinpath(index_file)
|
||||
if not traversable.is_file():
|
||||
return NOT_FOUND
|
||||
content_type = MIMETYPES.get(
|
||||
os.path.splitext(traversable.name)[1].lower(), FALLBACK_MIMETYPE)
|
||||
content_type = mimetypes.get(
|
||||
os.path.splitext(traversable.name)[1].lower(), fallback_mimetype)
|
||||
headers = {
|
||||
"Content-Type": content_type,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user