When using a browser's developer tools to monitor API calls and an API call is made with a request body encoded with gzip, how can you unzip the request body for viewing?
With Chrome, I can't copy/paste the request body (payload), but if I save the request to an HAR file and then use an HAR browsing tool to export the request body, gunzip complains of it not being a valid gzip file.
With Safari, I can copy/paste the request body, but the results using that method or exporting through HAR still result in an invalid gzip file.
For display or export purposes, both Chrome and Safari seem to be treating the request body as if each 8 bit byte is a unicode code point and then representing that content in UTF-8 encoding. For example, the first two bytes of the gzip header get represented as the three byte sequence of 0x1f, 0xc2, 0x8b rather than the correct 0x1f, 0xc2.
I've been unable to find any single macos utility that let's you reverse the above encoding, but the following will work:
Note that the UTF-16BE format specified to
iconvkeeps that utility from placing a BOM header in front of the output that would otherwise be present if UTF-16 format is used.