summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2021-04-16 13:31:44 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2021-04-19 12:01:16 +0200
commit90eab8679625d4a6d5d32b3e4fae498a48a68145 (patch)
tree760e80fc27aa2367ba98d6e2dec44011184aef11 /src/rest.c
parent2c6cef71d8f7a3251fced003c13258fad1cbc81d (diff)
#915 fix "response too large" error path
Otherwise, ogServer sends "200 OK" after a "500 Internal Server Error error" response.
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/rest.c b/src/rest.c
index d9b09d2..f778bc2 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -3976,17 +3976,21 @@ static int og_server_internal_error(struct og_client *cli)
static int og_client_ok(struct og_client *cli, char *buf_reply)
{
char buf[OG_MSG_RESPONSE_MAXLEN] = {};
- int err = 0, len;
+ int len;
len = snprintf(buf, sizeof(buf),
"HTTP/1.1 200 OK\r\nContent-Length: %ld\r\n\r\n%s",
strlen(buf_reply), buf_reply);
- if (len >= (int)sizeof(buf))
- err = og_server_internal_error(cli);
+ if (len >= (int)sizeof(buf)) {
+ syslog(LOG_ERR, "HTTP response to %s:%hu is too large\n",
+ inet_ntoa(cli->addr.sin_addr),
+ ntohs(cli->addr.sin_port));
+ return og_server_internal_error(cli);
+ }
send(og_client_socket(cli), buf, strlen(buf), 0);
- return err;
+ return 0;
}
int og_client_state_process_payload_rest(struct og_client *cli)
@@ -4416,14 +4420,7 @@ int og_client_state_process_payload_rest(struct og_client *cli)
if (err < 0)
return og_client_bad_request(cli);
- err = og_client_ok(cli, buf_reply);
- if (err < 0) {
- syslog(LOG_ERR, "HTTP response to %s:%hu is too large\n",
- inet_ntoa(cli->addr.sin_addr),
- ntohs(cli->addr.sin_port));
- }
-
- return err;
+ return og_client_ok(cli, buf_reply);
err_process_rest_payload:
json_decref(root);