我正在尝试使用以下脚本提供静态 .svgz 文件(压缩的 SVG):
http.ListenAndServe(":9090", http.FileServer(http.Dir("/srv/www/htdocs/")))
我收到以下错误:
This page contains the following errors:
error on line 1 at column 1: Encoding error
Below is a rendering of the page up to the first error.
如果我尝试通过 apache 获取相同的文件,该文件会正确显示。
有办法解决吗?
最佳答案
Go http.FileServer
不会自动为嗅探文件添加 Content-Encoding
。如果文件是预压缩的,您将需要添加适当的值。
您可以将 Content-Encoding: gzip
添加到标题中,并使用 http.ServeFile
在你的处理程序中。
关于http - Golang 静态文件 (SVGZ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38015870/