Skip to content

Commit

Permalink
Changed the order of handlers: protocol first, user second
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Jan 20, 2024
1 parent f883504 commit c1f34e8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
6 changes: 2 additions & 4 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) {
Expand Down
6 changes: 2 additions & 4 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit c1f34e8

Please sign in to comment.