1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-10-25 02:16:56 +08:00

Merge pull request #1531 from ipfs/fix/stream-header

only set stream header on streamed output
This commit is contained in:
Juan Benet
2015-07-28 12:59:54 -07:00

View File

@ -133,14 +133,6 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
func guessMimeType(res cmds.Response) (string, error) {
if _, ok := res.Output().(io.Reader); ok {
// 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
return "", nil
}
// Try to guess mimeType from the encoding option
enc, found, err := res.Request().Option(cmds.EncShort).String()
if err != nil {
@ -182,6 +174,14 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) {
h.Set(contentLengthHeader, strconv.FormatUint(res.Length(), 10))
}
if _, ok := res.Output().(io.Reader); ok {
// 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)
mime = ""
h.Set(streamHeader, "1")
}
// if output is a channel and user requested streaming channels,
// use chunk copier for the output
_, isChan := res.Output().(chan interface{})
@ -201,7 +201,6 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) {
if mime != "" {
h.Set(contentTypeHeader, mime)
}
h.Set(streamHeader, "1")
h.Set(transferEncodingHeader, "chunked")
if err := writeResponse(status, w, out); err != nil {