提交 f1c788d7 作者: Matt Bell 提交者: Juan Batiz-Benet

commands/http: Don't set Content-Type for stream outputs so browsers can…

commands/http: Don't set Content-Type for stream outputs so browsers can MIME-sniff the actual content type
上级 35983b48
......@@ -131,7 +131,7 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
contentType := httpRes.Header["Content-Type"][0]
contentType = strings.Split(contentType, ";")[0]
if contentType == "application/octet-stream" {
if len(httpRes.Header.Get(streamHeader)) > 0 {
res.SetOutput(httpRes.Body)
return res, nil
}
......
......@@ -18,6 +18,8 @@ type Handler struct {
var ErrNotFound = errors.New("404 page not found")
const streamHeader = "X-Stream-Output"
var mimeTypes = map[string]string{
cmds.JSON: "application/json",
cmds.XML: "application/xml",
......@@ -48,8 +50,12 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// set the Content-Type based on res output
if _, ok := res.Output().(io.Reader); ok {
// TODO: set based on actual Content-Type of file
w.Header().Set("Content-Type", "application/octet-stream")
// we don't set the Content-Type for streams, so that browsers can MIME-sniff the type themselves
// we set this header so clients have a way to know this is an output stream
// (not marshalled command output)
// TODO: set a specific Content-Type if the command response needs it to be a certain type
w.Header().Set(streamHeader, "1")
} else {
enc, _ := req.Option(cmds.EncShort)
encStr, ok := enc.(string)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论