【发布时间】:2017-01-24 00:10:37
【问题描述】:
我正在使用 http.FileServer 提供一个 mp3 文件目录,然后我的模板在 javascript 中使用 src。但是,响应使用Content-Type text/html 而不是audio/mpeg。如何设置 FileServer 响应的 mime 类型,我看到了这个问题 Setting the 'charset' property on the Content-Type header in the golang HTTP FileServer ,但我仍然不确定如何覆盖 mime 类型。
我的代码如下所示:
fs := http.FileServer(http.Dir(dir))
http.Handle("/media", http.StripPrefix("/media", fs))
http.HandleFunc("/", p.playlistHandler)
http.ListenAndServe(":5177", nil)
我得到的错误是:
HTTP "Content-Type" of "text/html" is not supported. Load of media resource http://localhost:5177/media/sample1.mp3 failed.
【问题讨论】:
标签: javascript go content-type mime fileserver