dongshu7162 2016-06-24 14:31
浏览 35

Golang静态文件(SVGZ)

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?

  • 写回答

2条回答 默认 最新

  • dongshi1102 2016-06-24 15:11
    关注

    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.

    评论

报告相同问题?