4

I've built an API endpoint with rails that accepts an XML payload in the request body. The XML has UTF8 characters in it but the client making the request didn't specify the charset in their Content-Type header so my controller is treating the string as an ACII 8-bit encoded string and it's causing problems in certain codepaths.

I'm unable to tell the client to set the charset to utf8 in their request because they have a legacy system and it's too much work for them to change. Is there a way I can tell my controllers or action dispatch to treat the request body as utf8 when no charset is provided in the Content-Type header so that codepaths that are deeper in the stack don't have to care about character encoding and just assume they'll always be handling UTF8 strings?

Adam Langsner
  • 1,276
  • 1
  • 15
  • 23
  • Hi Adam! Have you found a solution to this problem? – Richard-Degenne Aug 31 '21 at 13:14
  • 1
    @Richard-Degenne not that I'm aware of. I'm no longer working on that codebase, so I forget if or how I addressed the issue. Sorry I can't be more helpful. You may want to try digging into the rails source code to see how it handles request bodies, it's less scary than you think and you may find something – Adam Langsner Sep 01 '21 at 22:21
  • Hi, thanks for your reply. I'll do some digging, thanks for the advice. In the meantime, I've set up a workaround, I'll write an answer about it if I can find the time. – Richard-Degenne Sep 03 '21 at 07:15

0 Answers0