-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vweb: honor context.static_mime_types #18218
base: master
Are you sure you want to change the base?
vweb: honor context.static_mime_types #18218
Conversation
If you want to set a custom mime type you should do it with I don't think the |
Wouldn't that solution prevent us from setting custom mime types for a custom static file type? The use case I have is that I also serve .map files for javascript files, which are not set in the vweb.mime_type global. I think the ability to overwrite the set mime type is also important, as it could be that a client needs a specific content type set, which means you would have to write a whole custom handler instead of simply setting the mime type in the static map. |
I agree that custom static types/custom file mimetypes are important. The problem is that .map files have no defined standard mimetype (https://www.iana.org/assignments/media-types/media-types.xhtml). The current problem is that A custom file type could be send like this: ctx.set_content_type('my mime')
ctx.file(file) or I think the implementations of file, serve static and send_response_to_client should be changed. |
This would not allow for mixed custom mime type files in a single static folder. |
Ah I understand your use case. I still don't think the custom mime types should be placed in But how do you feel about a property |
I think that would be fine, but it has to be documented that the static_mime_types is basically a readonly property. I would implement the change in the following way:
I think your idea with the ability to(optionally) manually specify the mime type for the file is a good idea regardless of the other points and if it's ok I would send a pr for that. |
Yes also check the static files map. The changes look good to me, sorry for the confusion . |
Fixed in the new vweb module |
vweb only check if the mime type for a file exists in the global const vweb.mime_types, any mime type set in the request context gets ignored.
This PR fixes this by always first checking if the mime type exists in the context.static_mime_types, which also allows overriding the default mime type with a custom mime type.
🤖 Generated by Copilot at df03ce1
Improve MIME type handling for static files in vweb. Add custom MIME type support and use it in
vlib/vweb/vweb.v
.🤖 Generated by Copilot at df03ce1
ctx.static_mime_types
map when serving static files (link, link, link, link)