0

Im trying to serve static .svgz files (compressed SVG) with the below script:

http.ListenAndServe(":9090", http.FileServer(http.Dir("/srv/www/htdocs/")))

im getting the below error:

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.

if i try to fetch the same file through apache, the file is displaying properly.

is there a way to fix that?

aissa
  • 13
  • 6

2 Answers2

1

The Go http.FileServer doesn't automatically add Content-Encoding for sniffed files. If the file is pre-compressed you will need to add the appropriate value.

You can add Content-Encoding: gzip to the headers and, and use http.ServeFile in your handler.

JimB
  • 104,193
  • 13
  • 262
  • 255
  • thanks for the answer, any idea how this can be done using beego FW, svgz files are under static folder\ – aissa Jun 24 '16 at 15:32
0

Apache Header (tested in 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 (tested in 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 send "Content-Encoding: gzip" in header.

Working code (heavy inspired by https://groups.google.com/forum/#!topic/golang-nuts/Upzqsbu2zbo )

https://play.golang.org/p/eWxqHt9QbM

dmknob
  • 1
  • 2
  • I'm try in nginx, work with Chrome(51.0.2704.106) and fail on Firefox(45.0.2). And can't make work again with Go. No clue for now.. – dmknob Jun 26 '16 at 00:06