From 54d172e972067e4ddcfd11c613929af811754f99 Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Mon, 6 Apr 2020 11:24:19 +0200 Subject: #915: Reply 413 status code when no payload is too large If the payload is too long, then the API returns a 413 status code (following RFC 7231) instead of the resetting the communication without replying. This way it should be more clear when this problem is happening. The other commit I did related to the issue of the payload size (1d9d93c) said that ogAdmServer do not log anything when it receives a payload of a bigger size than supported, this is false. ogAdmServer prints the next message to the syslog when this happens: ogAdmServer[6824]: client request from 127.0.0.1:43552 is too long --- sources/ogAdmServer.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sources/ogAdmServer.c b/sources/ogAdmServer.c index 0984cdb..c465ffe 100644 --- a/sources/ogAdmServer.c +++ b/sources/ogAdmServer.c @@ -4358,6 +4358,16 @@ static int og_server_internal_error(struct og_client *cli) return -1; } +static int og_client_payload_too_large(struct og_client *cli) +{ + char buf[] = "HTTP/1.1 413 Payload Too Large\r\n" + "Content-Length: 0\r\n\r\n"; + + send(og_client_socket(cli), buf, strlen(buf), 0); + + return -1; +} + #define OG_MSG_RESPONSE_MAXLEN 65536 static int og_client_ok(struct og_client *cli, char *buf_reply) @@ -4688,6 +4698,7 @@ static void og_client_read_cb(struct ev_loop *loop, struct ev_io *io, int events if (cli->buf_len >= sizeof(cli->buf)) { syslog(LOG_ERR, "client request from %s:%hu is too long\n", inet_ntoa(cli->addr.sin_addr), ntohs(cli->addr.sin_port)); + og_client_payload_too_large(cli); goto close; } -- cgit v1.2.3-18-g5258