Possible bug with PostAsync

I’m not sure if this is a bug or if this is expected behavior, but data that is sent via the PostAsync method will be gzipped if it is over around 200 characters. This caused me about two hours of headache, because I had no idea what was going on. After a couple hours, I narrowed it down that it must be data compression that was causing the text to come through garbled- and I just assumed it would be gzipped, because that’s the de facto compression for POST data. (Though it’s usually uncompressed when accessed via PHP).

Using file_get_contents(“php://input”) returns the compressed POST data (assuming the data is long enough for the compression to be triggered). I’ve done a google search for this, and I can’t find anyone who has the same problem, which leads me to believe it may be a ROBLOX-specific problem.

If you ever encounter the same problem, here is the code to get the correct data: (Assuming you are posting JSON data directly and not application/urlencoded)

$fp = fopen('php://input', 'rb'); stream_filter_append($fp, 'dechunk', STREAM_FILTER_READ); $raw_data = stream_get_contents($fp); if (!mb_check_encoding($raw_data)){ $raw_data = gzinflate(substr($raw_data, 10, -8)); } $data = json_decode($raw_data, true);

Probably expected behavior, because you can’t accidentally compress large strings but not small ones very easily. If a writer/editor could document it, it would be good.