From 136c3e8200c4add0a41a723cab2e5cec8d31221e Mon Sep 17 00:00:00 2001 From: Sergey Lyubka <valenok@gmail.com> Date: Tue, 14 Jan 2014 13:57:55 +0000 Subject: [PATCH] Eat prior POST data in close_local_endpoint() --- mongoose.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mongoose.c b/mongoose.c index d262a1d04..1b2c77caa 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1901,6 +1901,7 @@ static void write_terminating_chunk(struct connection *conn) { } static void call_uri_handler(struct connection *conn) { + conn->mg_conn.content = conn->local_iobuf.buf; if (conn->endpoint.uh->handler(&conn->mg_conn)) { if (conn->flags & CONN_HEADERS_SENT) { write_terminating_chunk(conn); @@ -2186,7 +2187,6 @@ static void call_uri_handler_if_data_is_buffered(struct connection *conn) { struct iobuf *loc = &conn->local_iobuf; struct mg_connection *c = &conn->mg_conn; - c->content = loc->buf; #ifndef NO_WEBSOCKET if (conn->mg_conn.is_websocket) { do { } while (deliver_websocket_frame(conn)); @@ -3539,6 +3539,13 @@ static void log_access(const struct connection *conn, const char *path) { } #endif +static void gobble_prior_post_data(struct iobuf *io, int len) { + if (len > 0 && len <= io->len) { + memmove(io->buf, io->buf + len, io->len - len); + io->len -= len; + } +} + static void close_local_endpoint(struct connection *conn) { // Must be done before free() int keep_alive = should_keep_alive(&conn->mg_conn) && @@ -3556,6 +3563,10 @@ static void close_local_endpoint(struct connection *conn) { } #endif + if (conn->endpoint_type == EP_USER) { + gobble_prior_post_data(&conn->local_iobuf, conn->mg_conn.content_len); + } + conn->endpoint_type = EP_NONE; conn->flags = 0; conn->cl = conn->num_bytes_sent = conn->request_len = 0; -- GitLab