我试图使用以下脚本提供静态.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获取相同的文件,则文件正确显示。
有没有办法解决这个问题?
答案 0 :(得分:1)
Go For J = 1 To Sheets.Count
If J = Sheets.Count Then Exit For
Next J
Range("A1").Value = Val(Left(ShtNames(J), 4))
Range("B1").Value = Val(Left(ShtNames(J + 1), 4))
MsgBox ("Content of SaveSheet is " & SaveSheet)
SaveSheet = ShtNames(J)
If Val(Left(SaveSheet, 4)) < Val(Left(ShtNames(J + 1), 4)) Then SaveSheet = ShtNames(J + 1)
不会自动为嗅探文件添加http.FileServer
。如果文件是预压缩的,则需要添加适当的值。
您可以在标头中添加Content-Encoding
,并在处理程序中使用http.ServeFile
。
答案 1 :(得分:0)
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: gzip
Go 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 GMT
Apache在标题中发送“Content-Encoding:gzip”。
工作代码(重点受https://groups.google.com/forum/#!topic/golang-nuts/Upzqsbu2zbo启发)