Karl
Karl

Reputation: 14974

How do I signal to a web server that I'm posting gzipped data?

I have a client that will be posting large JSON files to an API server. Since the files are so compressable, I would like to gzip them and send the compressed data.

What I would like to know is: What is the best way to signal my intent to the server?

Basically, I want the reverse of Accept-encoding, such that the server would treat the data as only compressed for transport purposes, and automatically decompress the data before interpreting it according to the Content-Type.

This means that I can't set the Content-Type field to application/gzip because it needs to be application/json for the server to understand what the true uncompressed data encoding is.

Content-Transfer-Encoding looks like it would serve my purposes, but it was built with email in mind, and only supports 7bit, quoted-printable, base64, 8bit, and binary.

Does transparent compression/decompression for HTTP transport from client to server exist? And if not, what are the best practices for what I'm trying to achieve?

Upvotes: 4

Views: 445

Answers (1)

skaffman
skaffman

Reputation: 403501

The "reverse" of the Accept-encoding header is Content-encoding. This signals to the server that the content is gzipped:

Content-encoding: gzip

You're correct that you shouldn't use the Content-type header for this, since the gzip compression is purely a matter of how the request is encoded, not what it represents.

Upvotes: 2

Related Questions