request.body and StringIO encoding

I don’t know rails very much and I’m kind of struggling with a post body json string. ContentType headers in the request is set to “application/json; charset=UTF-8” and rails seems to parse it and put it in the parameters.

But my first instinct was to put the body in a string and proxy it to my http client who call an external service, but I got some encoding problem ASCII-8BIT != UTF-8.

If I understand request.body create a StringIO with hardcoded encoding ASCII-8BIT and request.body.string keep that encoding. Is there a reason for that?

So I need to do something like request.body.string.force_encoding(“utf8”) or params.to_json. What would be best practice for this use case?

This list is for discussion of the core features of the Rails
framework. For help with Rails, please ask rubonrails-talk or Stack
Overflow. Thanks.

Maybe I wasn’t clear in my last message, english isn’t my first language so I’m sorry if it was the case, but I’m pretty sure that the handling of the request body is a core feature of rails?

What I was trying to say is: Why does it ignore the content type of the request and use a hardcoded encoding when it creates the StringIO return by request.body? This behavior just feel wrong to me, but I asked to be sure that I didn’t miss something… anyway!

def body

if raw_post = @env[‘RAW_POST_DATA’]