unosquare / embedio

A tiny, cross-platform, module based web server for .NET
http://unosquare.github.io/embedio
Other
1.45k stars 175 forks source link

Cannot control charset in ContentType header #567

Open asesidaa opened 2 years ago

asesidaa commented 2 years ago

With the unreleased v3.5.0, it is now possible to remove the charset=utf-8 part in the content-type header by setting ContentEncoding to null.

However, when using FileModule to serve static files, there doesn't seem to be a way to set this.

Actually, I believe for mime types that are not for text, charset is not needed at all. Therefore, I would propose set ContentEncoding to null in FileModule, then add a whitelist (customizable) for those that need it.

rdeago commented 2 years ago

Hello @aesidaa, thanks for opening this issue.

Just a quick note to either my future self, or anyone taking up implementation:

I personally can't see this fixed in the immediate future; not in version 3 anyway. Is anyone willing to give it a shot?

rdeago commented 2 years ago

Oh and by the way:

unreleased v3.5.0

@geoperez 🙏

asesidaa commented 2 years ago

Hello @aesidaa, thanks for opening this issue.

Just a quick note to either my future self, or anyone taking up implementation:

  • MIME type providers need to be able to specify whether a MIME type needs an encoding;
  • FileModule needs a callback or similar mechanism to determine the actual encoding to set, given the served file;
  • for immutable file providers at the least, the association between path and encoding should be cached.

I personally can't see this fixed in the immediate future; not in version 3 anyway. Is anyone willing to give it a shot?

I currently write a quick workaround according to https://stackoverflow.com/questions/70643383/which-mime-types-contain-charset-utf-8-directive, only add charset=utf-8 for text/* and common ones like application/json, since this is really only needed for content that are consumed as text.