From c1f34e816cc2de96e4977cee99f256899878f191 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Sat, 20 Jan 2024 09:43:24 +0000 Subject: [PATCH] Changed the order of handlers: protocol first, user second --- mongoose.c | 6 ++---- src/event.c | 6 ++---- test/unit_test.c | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/mongoose.c b/mongoose.c index e32264803d3..fa61ae961d7 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1345,11 +1345,9 @@ void mg_call(struct mg_connection *c, int ev, void *ev_data) { MG_PROF_ADD(c, names[ev]); } #endif - // Run user-defined handler first, in order to give it an ability - // to intercept processing (e.g. clean input buffer) before the - // protocol handler kicks in - if (c->fn != NULL) c->fn(c, ev, ev_data); + // Fire protocol handler first, user handler second. See #2559 if (c->pfn != NULL) c->pfn(c, ev, ev_data); + if (c->fn != NULL) c->fn(c, ev, ev_data); } void mg_error(struct mg_connection *c, const char *fmt, ...) { diff --git a/src/event.c b/src/event.c index e6217f40f5f..8c0fa211b86 100644 --- a/src/event.c +++ b/src/event.c @@ -16,11 +16,9 @@ void mg_call(struct mg_connection *c, int ev, void *ev_data) { MG_PROF_ADD(c, names[ev]); } #endif - // Run user-defined handler first, in order to give it an ability - // to intercept processing (e.g. clean input buffer) before the - // protocol handler kicks in - if (c->fn != NULL) c->fn(c, ev, ev_data); + // Fire protocol handler first, user handler second. See #2559 if (c->pfn != NULL) c->pfn(c, ev, ev_data); + if (c->fn != NULL) c->fn(c, ev, ev_data); } void mg_error(struct mg_connection *c, const char *fmt, ...) { diff --git a/test/unit_test.c b/test/unit_test.c index a219b2a30ca..88f2581d8b0 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -1391,7 +1391,7 @@ static void test_http_no_content_length(void) { for (i = 0; i < 1000 && strchr(buf2, 'c') == NULL; i++) mg_mgr_poll(&mgr, 10); MG_INFO(("[%s] [%s]", buf1, buf2)); ASSERT(strcmp(buf1, "mc") == 0); - ASSERT(strcmp(buf2, "cm") == 0); // See #1475 + ASSERT(strcmp(buf2, "mc") == 0); mg_mgr_free(&mgr); ASSERT(mgr.conns == NULL); }