我正在尝试使用以下脚本提供静态.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获取相同的文件,该文件可以正常显示。
有没有办法解决这个问题?
发布于 2016-06-24 23:11:56
Go http.FileServer不会为嗅探到的文件自动添加Content-Encoding。如果文件是预压缩的,则需要添加适当的值。
您可以将Content-Encoding: gzip添加到标头和,并在处理程序中使用http.ServeFile。
发布于 2016-06-24 23:42:30
Apache Header (在Chrome中测试):
HTTP/1.1 200 OK
Date: Fri, 24 Jun 2016 14:56:03 GMT
Server: Apache
Last-Modified: Fri, 24 Jun 2016 14:43:34 GMT
ETag: "443-5360731fd11b2"
Accept-Ranges: bytes
Content-Length: 1091
Keep-Alive: timeout=15, max=98
Connection: Keep-Alive
Content-Type: image/svg+xml
Content-Encoding: gzipGo Header (Chrome测试):
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 1091
Content-Type: image/svg+xml
Last-Modified: Fri, 24 Jun 2016 14:43:34 GMT
Date: Fri, 24 Jun 2016 14:54:56 GMTApache在标题中发送"Content-Encoding: gzip“。
工作代码(大量受https://groups.google.com/forum/#!topic/golang-nuts/Upzqsbu2zbo启发)
https://stackoverflow.com/questions/38015870
复制相似问题