http - Golang 静态文件 (SVGZ)

标签 http go svgz

我正在尝试使用以下脚本提供静态 .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/

相关文章:

c# - C# 中的 TypeScript 数组等价物

go - 如何调用父方法并将扩展父结构的任何子结构作为 Golang 中的参数传递

go - golang安装覆盖包时出现的问题

json - 如何使用 Go 部分解析 JSON?

svg - 在 html 服务器中使用 svgz

SVGZ 文件格式

python - 执行多个请求时如何加速 Python urllib2

http - 多线程Go for HTTP get

ios - iphone(ios) 如何在服务器上上传和下载数据

javascript - 如何用JavaScript解压SVGZ?