简体   繁体   English

Jetty不提供具有正确内容类型的静态SVGZ文件

[英]Jetty does not serve static SVGZ files with correct content type

I added the extension svgz to serve compressed svg files, but jetty issues the wrong content encoding. 我添加了扩展名svgz来提供压缩的svg文件,但是jetty发出了错误的内容编码。 I believe it should be a gzip encoding. 我相信应该是gzip编码。

Does anyone know how to configure Jetty to serve static SVGZ files? 有谁知道如何配置Jetty以提供静态SVGZ文件? This is pretty important, as these files are typically very large in size before compression. 这非常重要,因为压缩前这些文件的大小通常非常大。

Files with extension SVGZ are just SVG files compressed with GZip compression. 扩展名为SVGZ的文件只是通过GZip压缩压缩的SVG文件。 Rename the file extension, if the file is logo.svgz rename it to logo.svg.gz but keep it compressed. 重命名文件扩展名,如果文件是logo.svgz ,则将其重命名为logo.svg.gz但保持压缩状态。

When compressed SVG files are sent from a Web Server, there are 2 pieces of information that should be in the response headers. 从Web服务器发送压缩的SVG文件时,响应标头中应包含2条信息。

Content-Type: image/svg+xml
Content-Encoding: gzip

Typically, a MIME Type mapping is established in the ${jetty.home}/etc/webdefault.xml file (look for <mime-mapping> ) for the DefaultServlet to use to serve this static file with the appropriate Content-Type, however, this is also compressed, so that means all of the Gzip logic should kick in. 通常,将在${jetty.home}/etc/webdefault.xml文件(查找<mime-mapping> )中建立MIME类型映射,以使DefaultServlet可以为该静态文件提供适当的Content-Type。 ,这也是压缩的,因此所有Gzip逻辑都应加入。

The DefaultServlet will set the appropriate Content-Encoding header if it sees a .gz file extension present for the file requested. 如果DefaultServlet看到所请求文件的.gz文件扩展名,则将设置适当的Content-Encoding标头。

In other words, your http client (browser) can request the file logo.svg , but DefaultServlet will serve from the file contents from logo.svg.gz with Content-Encoding set to gzip. 换句话说,您的http客户端(浏览器)可以请求文件logo.svg ,但是DefaultServlet将通过logo.svg.gz的文件内容( Content-Encoding设置为gzip)提供服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM