body encoding issues

32 views
Skip to first unread message

Ben Bonnet

unread,
Feb 20, 2019, 7:02:45 AM2/20/19
to Roda

Hello,


Currently porting an app to roda, among other things, it ingests webhooks from shopify. Having an issue about body encoding, completely unable to understand where and how it could be solved


So far with our previous sinatra snippet :


...

request.body.rewind

data = request.body.read

...


data was encoded in ascii-8-bit


As below : 


"{\"...as a single left breast pocket and rounded buttoned cuffs.\\u003cbr\\u003e\\u003cbr\\u003eDetails: \\u0



In the roda app, it's plain utf-8


"{\"...st pocket and rounded buttoned cuffs.<br><br>Details: <br>Shell buttons...


As we've have to compare signatures though the body params; we're stuck


We're using the following plugins :


plugin :head

plugin :hooks

plugin :json_parser

plugin :multi_route

plugin :status_handler

plugin :slash_path_empty

plugin :all_verbs

plugin :halt

plugin :request_headers

plugin :default_headers


I tried removing json_parser, with no success;


I'm might obviously lack of understanding about all encoding issues, but is there something to do to preserve the 'default' encoding we could have had witnessed in the original example ?

jeremy...@gmail.com

unread,
Feb 20, 2019, 9:43:58 AM2/20/19
to Roda
On Wednesday, February 20, 2019 at 4:02:45 AM UTC-8, Ben Bonnet wrote:

Hello,


Currently porting an app to roda, among other things, it ingests webhooks from shopify. Having an issue about body encoding, completely unable to understand where and how it could be solved


So far with our previous sinatra snippet :


...

request.body.rewind

data = request.body.read

...


data was encoded in ascii-8-bit


As below : 


"{\"...as a single left breast pocket and rounded buttoned cuffs.\\u003cbr\\u003e\\u003cbr\\u003eDetails: \\u0



In the roda app, it's plain utf-8


"{\"...st pocket and rounded buttoned cuffs.<br><br>Details: <br>Shell buttons...


This is quite odd.  request.body is not a Roda method, but a Rack::Request method.  Are you using the same webserver and version of rack in the Roda app that you were using in the Sinatra app?  Does the issue exist if you use a pure-rack application?:

run(lambda{|env| p env['rack.input'].read; [200, {}, []]})

Thanks,
Jeremy

Elijah Goh, Chong Hui

unread,
Feb 20, 2019, 8:28:45 PM2/20/19
to Roda
Sounds like it could be an encoding thing.

Either encode it to ascii or set your LANG env.

http://ruby-doc.org/core-2.1.2/Encoding.html#class-Encoding-label-External+encoding

Ben Bonnet

unread,
Feb 21, 2019, 5:58:49 AM2/21/19
to Roda
hello, sorry for that :/

I was just not aware that request.body.read is not the same as req.params
And was in doubt that it was available in roda

sorry and thx for your help
Reply all
Reply to author
Forward
0 new messages