diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2019-09-19 15:49:39 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-09-19 16:06:03 +0200 |
commit | c1c89e196c7ecbc91dd1f3237cd546ef633490c4 (patch) | |
tree | 3863be29a0c295dc8f61cd8e5b82694d9607edb8 /sources/ogAdmServer.cpp | |
parent | 55edb404b754c3dd817289e35d67505a476e7dbf (diff) |
#915: Return 400 status code in POST methods when no payload is attached
If no payload is attached to method that requires a payload, then the API
returns a 400 status code (following RFC 7231) instead of the previous 404.
test_0001_get_clients.py is also modified to fit the new status code.
Diffstat (limited to 'sources/ogAdmServer.cpp')
-rw-r--r-- | sources/ogAdmServer.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp index 357bf01..6401fe1 100644 --- a/sources/ogAdmServer.cpp +++ b/sources/ogAdmServer.cpp @@ -3933,6 +3933,15 @@ static int og_client_method_not_found(struct og_client *cli) return -1; } +static int og_client_bad_request(struct og_client *cli) +{ + char buf[] = "HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n"; + + send(og_client_socket(cli), buf, strlen(buf), 0); + + return -1; +} + static int og_client_not_found(struct og_client *cli) { char buf[] = "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n"; @@ -4032,7 +4041,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) if (method == OG_METHOD_POST && !root) { syslog(LOG_ERR, "command clients with no payload\n"); - return og_client_not_found(cli); + return og_client_bad_request(cli); } switch (method) { case OG_METHOD_POST: @@ -4048,7 +4057,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) if (!root) { syslog(LOG_ERR, "command wol with no payload\n"); - return og_client_not_found(cli); + return og_client_bad_request(cli); } err = og_cmd_wol(root, ¶ms); } else if (!strncmp(cmd, "shell/run", strlen("shell/run"))) { @@ -4057,7 +4066,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) if (!root) { syslog(LOG_ERR, "command run with no payload\n"); - return og_client_not_found(cli); + return og_client_bad_request(cli); } err = og_cmd_run_post(root, ¶ms); } else if (!strncmp(cmd, "shell/output", strlen("shell/output"))) { @@ -4066,7 +4075,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) if (!root) { syslog(LOG_ERR, "command output with no payload\n"); - return og_client_not_found(cli); + return og_client_bad_request(cli); } err = og_cmd_run_get(root, ¶ms, buf_reply); @@ -4076,7 +4085,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) if (!root) { syslog(LOG_ERR, "command session with no payload\n"); - return og_client_not_found(cli); + return og_client_bad_request(cli); } err = og_cmd_session(root, ¶ms); } else if (!strncmp(cmd, "poweroff", strlen("poweroff"))) { @@ -4085,7 +4094,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) if (!root) { syslog(LOG_ERR, "command poweroff with no payload\n"); - return og_client_not_found(cli); + return og_client_bad_request(cli); } err = og_cmd_poweroff(root, ¶ms); } else if (!strncmp(cmd, "reboot", strlen("reboot"))) { @@ -4094,7 +4103,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) if (!root) { syslog(LOG_ERR, "command reboot with no payload\n"); - return og_client_not_found(cli); + return og_client_bad_request(cli); } err = og_cmd_reboot(root, ¶ms); } else if (!strncmp(cmd, "stop", strlen("stop"))) { @@ -4103,7 +4112,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) if (!root) { syslog(LOG_ERR, "command stop with no payload\n"); - return og_client_not_found(cli); + return og_client_bad_request(cli); } err = og_cmd_stop(root, ¶ms); } else if (!strncmp(cmd, "refresh", strlen("refresh"))) { @@ -4112,7 +4121,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) if (!root) { syslog(LOG_ERR, "command refresh with no payload\n"); - return og_client_not_found(cli); + return og_client_bad_request(cli); } err = og_cmd_refresh(root, ¶ms); } else if (!strncmp(cmd, "hardware", strlen("hardware"))) { @@ -4121,7 +4130,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) if (!root) { syslog(LOG_ERR, "command hardware with no payload\n"); - return og_client_not_found(cli); + return og_client_bad_request(cli); } err = og_cmd_hardware(root, ¶ms); } else if (!strncmp(cmd, "software", strlen("software"))) { @@ -4130,7 +4139,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) if (!root) { syslog(LOG_ERR, "command software with no payload\n"); - return og_client_not_found(cli); + return og_client_bad_request(cli); } err = og_cmd_software(root, ¶ms); } else { |