如何向Web服务器发出我正在发布压缩数据的信号? [英] 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?
基本上,我希望与Accept-encoding
相反,以便服务器将数据视为仅出于传输目的而压缩,并在根据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
,8bit
和binary
.
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?
推荐答案
Accept-encoding
标头的反向"为Content-encoding
.这会向服务器发出内容已压缩的信号:
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服务器发出我正在发布压缩数据的信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!