当Web服务器返回JPEG图像(mime type image / jpeg)时,它是如何编码的?

问题描述:

如果您向Web服务器发出HTTP请求,并且它返回类型为image / jpeg的响应,那么二进制数据如何实际编码?它是图像的原始字节级内容,或者它的某些基于字符的表示(例如base64)?

If you make an HTTP request to a web server, and it returns a response of type image/jpeg, how is the binary data actually encoded? Is it the original byte-level content of the image that goes across the wire, or some character-based representation of it (e.g. base64)?

编码的传输数据由 Content-Encoding HTTP响应头指定(参见 RFC2616 第14.11和3.5节。如果存在,它可以是 gzip 压缩,或 deflate 压缩数据(HTTP 1.1中没有定义其他数据)。如果不是,则数据基于 Content-Type HTTP响应头(MIME类型)进行原始编码。 Content-Encoding Accept-Encoding HTTP请求标头值以及Web服务器是否支持请求编码确定。

The encoded transfered data is specified by the Content-Encoding HTTP response header (see HTTP 1.1 specifications in RFC2616 section 14.11 and 3.5). If present, it can be either gzip, compress, or deflate compressed data (no others are defined in HTTP 1.1). If not, the data is in original encoding based on the Content-Type HTTP response header (the MIME type). The Content-Encoding is determined by the Accept-Encoding HTTP request header value and whether the web server support requested encoding.

在您的情况下,如果缺少 Content-Encoding HTTP响应标头,则数据与文件内容。否则,它使用指定的编码进行压缩。例如: GZip Deflate

In your case, if the Content-Encoding HTTP response header is absent, the data is exactly the same as the file contents. Otherwise, it's compressed with the specified encoding. e.g.: GZip or Deflate.