only set stream header on streamed output
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Jul 28, 2015 at 08:18 UTC
2cad99d5efcef1e732ec7b7ab33b90fad68acec7
1 file changed
+5
-9
commands/http/handler.go
+5
-9
@@ -133,14 +133,6 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
133
}
134
135
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
-
136
// Try to guess mimeType from the encoding option
137
enc, found, err := res.Request().Option(cmds.EncShort).String()
138
if err != nil {
@@ -182,6 +174,11 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) {
174
h.Set(contentLengthHeader, strconv.FormatUint(res.Length(), 10))
175
}
176
177
+ if _, ok := res.Output().(io.Reader); ok {
178
+ mime = ""
179
+ h.Set(streamHeader, "1")
180
+ }
181
+
182
// if output is a channel and user requested streaming channels,
183
// use chunk copier for the output
184
_, isChan := res.Output().(chan interface{})
@@ -201,7 +198,6 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) {
198
if mime != "" {
199
h.Set(contentTypeHeader, mime)
200
}
204
- h.Set(streamHeader, "1")
201
h.Set(transferEncodingHeader, "chunked")
202
203
if err := writeResponse(status, w, out); err != nil {