1

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

Duncan McGregor
  • 17,665
  • 12
  • 64
  • 118

1 Answers1

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.

ᴇʟᴇvᴀтᴇ
  • 12,285
  • 4
  • 43
  • 66
  • It seems I'd have to do this for every text/ mapping, which is a shame. Why on earth I can't just subclass MimeMappings I don't know. – Duncan McGregor Jun 24 '16 at 21:20
  • 1
    Yes, they seem to have explicitly denied that without explaining why. Maybe you could submit a patch that makes the constructor more visible? – ᴇʟᴇvᴀтᴇ Jun 25 '16 at 06:09