diff --git a/commands/http/client.go b/commands/http/client.go index 748f50365135213bdbb85eb0f8a2fcd239f8599c..9e8c1d3a7f4ef340b1a76874f9721db55f3afeb7 100644 --- a/commands/http/client.go +++ b/commands/http/client.go @@ -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 } diff --git a/commands/http/handler.go b/commands/http/handler.go index e5959b4a8a09fc1f8a70d12d1d65f06e08056343..a8fec766e716f6858b5e02a9a0648dd5cc5a4e00 100644 --- a/commands/http/handler.go +++ b/commands/http/handler.go @@ -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)