Vladimir Dyuzhev
MockMotor Creator
GZip, Deflate, Brotli and ZStd in Requests
The payload compression is not beneficial(***) within local networks, but occassionally some clients do send compressed requests
Until Now, Compression was not Supported
The HTTP protocol supports a few compression schemes for requests. The clients never or very rarely compress the requests inside the local networks. It is not considered beneficial.
Because of this, MM didn’t support compressed requests. The response can still be mocked, but no payload data is available for scripting.
But it is Time
However, I just ran into a client that sends GZipped requests, which means one thing - it is time to implement the decompression of request payloads.
What is Supported
Easier said than done - I’m running on an outdated Jetty version (9), but after some coding around, I implemented these compression schemes:
GZip
Deflate
Brotli
ZStd
Identity (i.e. no compression)
What is not Supported?
Not supported, due to being legacy or never seen in APIs in the wild:
Compress
DCB
DCZ
Also, the stacked compression (e.g. first compress, then gzip) is not supported. Never even knew it was spelled out in the spec. What a weird thing to do!
Interesting Performance Consideration for HTTPS
(***) I always thought that using compression in the local (internal corporate) networks is a waste. A delay introduced by compression and then decompression would be greater than the gain from a smaller payload travelling via the very fast internal network.
However, it is not always true.
Some (maybe all modern ones?) of the HTTPS ciphers perform multiple passes over the blocks being encrypted. It takes noticable CPU time. If we compress the payload before sending it over an HTTPS connection, the cypher has a much smaller workload, which in turn saves CPU time compared to sending an uncompressed payload.
I.e.
Uncompressed 1M payload: cypher makes N passes over 1M payload
Compressed 1M payload: gzip (or any other compressor) makes one pass over 1M payload + cypher makes N passes over 100K payload
A performance win!
AI created no part of this text. It isn't the Butlerian Jihad, but it is something anyone could do.