1
0
mirror of https://github.com/rclone/rclone.git synced 2026-01-04 17:43:50 +00:00

fs rc: fixes incorrect Content-Type in HTTP API - fixes #7726

This commit is contained in:
Kyle Reynolds
2024-04-05 14:06:41 -06:00
committed by Nick Craig-Wood
parent 5323a21898
commit 47cbddbd27
2 changed files with 54 additions and 1 deletions

View File

@@ -200,6 +200,7 @@ func (s *Server) Serve() error {
func writeError(path string, in rc.Params, w http.ResponseWriter, err error, status int) {
fs.Errorf(nil, "rc: %q: error: %v", path, err)
params, status := rc.Error(path, in, err, status)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
err = rc.WriteJSON(w, params)
if err != nil {
@@ -294,6 +295,7 @@ func (s *Server) handlePost(w http.ResponseWriter, r *http.Request, path string)
}
fs.Debugf(nil, "rc: %q: reply %+v: %v", path, out, err)
w.Header().Set("Content-Type", "application/json")
err = rc.WriteJSON(w, out)
if err != nil {
// can't return the error at this point - but have a go anyway