Skip to content

Commit 2cad99d

Browse files
committedJul 28, 2015
only set stream header on streamed output
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent 075e687 commit 2cad99d

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed
 

‎commands/http/handler.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,6 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
133133
}
134134

135135
func guessMimeType(res cmds.Response) (string, error) {
136-
if _, ok := res.Output().(io.Reader); ok {
137-
// we don't set the Content-Type for streams, so that browsers can MIME-sniff the type themselves
138-
// we set this header so clients have a way to know this is an output stream
139-
// (not marshalled command output)
140-
// TODO: set a specific Content-Type if the command response needs it to be a certain type
141-
return "", nil
142-
}
143-
144136
// Try to guess mimeType from the encoding option
145137
enc, found, err := res.Request().Option(cmds.EncShort).String()
146138
if err != nil {
@@ -182,6 +174,11 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) {
182174
h.Set(contentLengthHeader, strconv.FormatUint(res.Length(), 10))
183175
}
184176

177+
if _, ok := res.Output().(io.Reader); ok {
178+
mime = ""
179+
h.Set(streamHeader, "1")
180+
}
181+
185182
// if output is a channel and user requested streaming channels,
186183
// use chunk copier for the output
187184
_, isChan := res.Output().(chan interface{})
@@ -201,7 +198,6 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) {
201198
if mime != "" {
202199
h.Set(contentTypeHeader, mime)
203200
}
204-
h.Set(streamHeader, "1")
205201
h.Set(transferEncodingHeader, "chunked")
206202

207203
if err := writeResponse(status, w, out); err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.