How can I configure Undertow to add a charset to t

2019-07-25 12:03发布

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/'?

标签: java undertow
1条回答
Emotional °昔
2楼-- · 2019-07-25 12:28

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.

查看更多
登录 后发表回答