如何向Web服务器发出信号,表明我正在发布gzip压缩数据? [英] How do I signal to a web server that I'm posting gzipped data?
问题描述
我有一个将大型JSON文件发布到API服务器的客户端。由于这些文件是可压缩的,我想对它们进行gzip并发送压缩数据。
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?
基本上,我想要反向接受编码
,这样服务器就会对待数据仅作为传输目的进行压缩,并在根据 Content-Type
解释数据之前自动解压缩数据。
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
.
这意味着我无法将 Content-Type
字段设置为 application / gzip
,因为它需要是 application / json
让服务器了解真正的未压缩数据编码是什么。
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
看起来像是出于我的目的,但它是在考虑电子邮件的情况下构建的,只支持 7bit
, quoted-printable
, base64
, 8位
和二进制
。
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
.
是否存在从客户端到服务器的HTTP传输的透明压缩/解压缩?如果没有,那么我想要达到的最佳实践是什么?
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?
推荐答案
<反向接受编码
标头是内容编码
。这向服务器发出gzip压缩内容的信号:
The "reverse" of the Accept-encoding
header is Content-encoding
. This signals to the server that the content is gzipped:
Content-encoding: gzip
你是正确的,你不应该使用 Content-type
标题,因为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.
这篇关于如何向Web服务器发出信号,表明我正在发布gzip压缩数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!