admin/api: bytes handlers now returned data as application/octet-stream
This commit is contained in:
parent
84774207c8
commit
69640506d0
@ -24,8 +24,6 @@ func apiHandler(f DispatchFunction) func(http.ResponseWriter, *http.Request, htt
|
|||||||
}
|
}
|
||||||
log.Printf("%s \"%s %s\" [%s]\n", r.RemoteAddr, r.Method, r.URL.Path, r.UserAgent())
|
log.Printf("%s \"%s %s\" [%s]\n", r.RemoteAddr, r.Method, r.URL.Path, r.UserAgent())
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
var ret interface{}
|
var ret interface{}
|
||||||
var err error = nil
|
var err error = nil
|
||||||
|
|
||||||
@ -64,14 +62,20 @@ func apiHandler(f DispatchFunction) func(http.ResponseWriter, *http.Request, htt
|
|||||||
}
|
}
|
||||||
|
|
||||||
if str, found := ret.(string); found {
|
if str, found := ret.(string); found {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(resStatus)
|
w.WriteHeader(resStatus)
|
||||||
io.WriteString(w, str)
|
io.WriteString(w, str)
|
||||||
} else if bts, found := ret.([]byte); found {
|
} else if bts, found := ret.([]byte); found {
|
||||||
|
w.Header().Set("Content-Type", "application/octet-stream")
|
||||||
|
w.Header().Set("Content-Disposition", "attachment")
|
||||||
|
w.Header().Set("Content-Transfer-Encoding", "binary")
|
||||||
w.WriteHeader(resStatus)
|
w.WriteHeader(resStatus)
|
||||||
w.Write(bts)
|
w.Write(bts)
|
||||||
} else if j, err := json.Marshal(ret); err != nil {
|
} else if j, err := json.Marshal(ret); err != nil {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
http.Error(w, fmt.Sprintf("{\"errmsg\":%q}", err), http.StatusInternalServerError)
|
http.Error(w, fmt.Sprintf("{\"errmsg\":%q}", err), http.StatusInternalServerError)
|
||||||
} else {
|
} else {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(resStatus)
|
w.WriteHeader(resStatus)
|
||||||
w.Write(j)
|
w.Write(j)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user