commit e9292a95ec87a3c4fe1c1662fae4b3cf8d887bbb
parent 02634d01472ce8fe4b50f99c31db0327e27ed7e8
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Fri, 4 Mar 2022 15:52:06 +0300
connection.c: added function to check used reply
Log warning if response has body, but no body is allowed for this
connection.
Diffstat:
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
@@ -1815,6 +1815,32 @@ setup_reply_properties (struct MHD_Connection *connection)
/**
+ * Check whether queued response is suitable for @a connection.
+ * @param connection to connection to check
+ */
+static void
+check_connection_reply (struct MHD_Connection *connection)
+{
+ struct MHD_Connection *const c = connection; /**< a short alias */
+ struct MHD_Response *const r = c->response; /**< a short alias */
+ mhd_assert (c->rp_props.set);
+
+#ifdef HAVE_MESSAGES
+ if ((! c->rp_props.use_reply_body_headers) && (0 != r->total_size))
+ {
+ MHD_DLOG (c->daemon,
+ _ ("This reply with response code %u cannot use reply body. "
+ "Non-empty response body is ignored and not used.\n"),
+ (unsigned) (c->responseCode & (~MHD_ICY_FLAG)));
+ }
+#else
+ (void) c; /* Mute compiler warning */
+ (void) r; /* Mute compiler warning */
+#endif
+}
+
+
+/**
* Append data to the buffer if enough space is available,
* update position.
* @param[out] buf the buffer to append data to
@@ -2012,6 +2038,8 @@ build_header_response (struct MHD_Connection *connection)
! c->rp_props.use_reply_body_headers);
#endif /* UPGRADE_SUPPORT */
+ check_connection_reply (c);
+
rcode = (unsigned) (c->responseCode & (~MHD_ICY_FLAG));
if (MHD_CONN_MUST_CLOSE == c->keepalive)
{