0

I receive a json object encoded with jwt, in the middleware i want to build post params after decode the message

params = JSON.parse(env['rack.input'].read)
json_decoded = decode_data(params['data'], secret_key)
puts "DECODED: #{json_decoded[0]}"
env["rack.input"] = StringIO.new(json_decoded[0].to_s)
>>> CODE HERE

status, headers, response = @app.call(env)
[status, headers, response]

on console

{"name"=>"xyz", "description"=>"xyz"}

ActionDispatch::Http::Parameters::ParseError (822: unexpected token at '{"name"=>"xyz", "description"=>"xyz"}'):

how I can build post params for pass to rails

  • https://stackoverflow.com/a/3970799/1376448 see if this helps you. `rewind` and changing content length header. – kiddorails Sep 15 '17 at 21:01
  • the solution was `rewind` + parse json by the parser defined for request's content mime type (ActionDispatch::ParamsParser::ParseError 822) `env["rack.input"] = StringIO.new(json_decoded[0].to_json.to_s)` `env["rack.input"].rewind` ` thanks – Manuel Michelangelli Sep 16 '17 at 13:13

0 Answers0