Simplify body closing logic for the rewrite middleware.