Backport post_handler.c improvement from upstream