Utils.safeJSONParse uses JSON.parse under the hood which
cannot convert form url encoded query strings (which is what the
string format of the binary data/Buffer string would be) to a
"JSON Object" so we'll use the core node.js module, querystring
to parse it. However, this parser might not automagically convert
the Buffer to a string, so we'll convert it first and then parse
it using the correct parser.
For some reason, we need to have the content-type to use
application/json. This is no matter if the body is correctly
parsed or not. My guess is there is some method in hydra library
that requires the header content type to be json rather or the
body is parsed in a string format rather than a JSON format.
This change seems to be the cleanest with minimal changes to the surface
area without also updating any other libraries (like hydra or UMF). Previously, we are
unable to send any requests with form url encoded body params whereas
now form url encoded body params will be converted to json body
params.
Utils.safeJSONParse
usesJSON.parse
under the hood which cannot convert form url encoded query strings (which is what the string format of the binary data/Buffer string would be) to a "JSON Object" so we'll use the core node.js module,querystring
to parse it. However, this parser might not automagically convert the Buffer to a string, so we'll convert it first and then parse it using the correct parser.content-type
to useapplication/json
. This is no matter if the body is correctly parsed or not. My guess is there is some method inhydra
library that requires the header content type to be json rather or the body is parsed in a string format rather than a JSON format.This change seems to be the cleanest with minimal changes to the surface area without also updating any other libraries (like
hydra
orUMF
). Previously, we are unable to send any requests with form url encoded body params whereas now form url encoded body params will be converted to json body params.Pre-change logs
Post-change logs