Command error handling does not work well

Issue #1025 resolved
Lutz Mader created an issue

Hello,
the command error response handling is stil broken with 5.30.0. See issue #1009 additional information about the little glitch.

For something like

monit status unknown

I got a response with something like this

<html><head><title>400 Bad Request</title></head><body bgcolor=#FFFFFF><h2>Bad Request</h2>Service 'unknown' not found<hr><a href='http://mmonit.com/monit/'<font> size=-1>monit 5.30.0</font></a></body></html>

But the used header said (in "client.c", see "_parseHttpResponse")

HTTP/1.0 302 Moved Temporarily

Therefore, the status is 302 and not 400 and the response will not parsed properly (based on "status < 300 || status == SC_MOVED_TEMPORARILY").

To get a proper status to handle errors again without overriding the status in "doPost" (in "cervlet.c") 302 should be send for status codes below 300 only.

else
    handle_service_action(req, res);
if (STR_DEF(req->url)) {
// Send a proper status to handle errors
    if (res->status <= 300) {
        // #1009: Redirect back to the same url so a reload in the browser does not perform a POST again
                set_status(res, SC_MOVED_TEMPORARILY);
                set_header(res, "Location", "%s", req->url);
            }
    }
}

A suggestion only,
with regards,
Lutz

Comments (1)

  1. Tildeslash repo owner

    Fixed: Issue #1025: If Monit 5.30.0 CLI action was executed for non-existent service name, the error message was not reported properly. Thanks to Lutz Mader for fix.

    → <<cset 6be6f8e9f778>>

  2. Log in to comment