How can I configure Undertow to add a charset to text/ content types?

走远了吗. 提交于 2019-12-11 13:57:28

问题


I have a programmatically started Undertow server (not running as part of any container).

My static resources, served with a ResourceHander on a PathResourceManager are UTF-8 encoded, but the mime type sent by the PathResourceManager does not include a charset.

I'd rather not stoop to building a whole new MimeMappings table and installing it.

Is there any way to use a handler to add the charset to responses with a CONTENT-TYPE starting with `text/'?


回答1:


I did this in my code:

handler = path()
        .addPrefixPath("/", resource(new FileResourceManager(webStaticDir, 1024))
        .setMimeMappings(MimeMappings.builder(true)
                .addMapping("html", "text/html;charset=utf-8")
                .build()));

Perhaps you can adapt it for your situation.



来源:https://stackoverflow.com/questions/38018827/how-can-i-configure-undertow-to-add-a-charset-to-text-content-types

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!