From bc1d1df38d7803ce9fdae05fc5129051eeed89e0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 6 Jun 2010 00:43:34 +0000 Subject: when wrapping the body, body.close writes the log We no longer write the log out at the end of the body.each call. This is a behavioral change, but fortunately all Rack servers I've seen call body.close inside an ensure. This allows us to later pass along the "to_path" method and not rely on "each" to write the log. --- ext/clogger_ext/clogger.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'ext') diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c index 415fe32..100392d 100644 --- a/ext/clogger_ext/clogger.c +++ b/ext/clogger_ext/clogger.c @@ -638,12 +638,11 @@ static VALUE body_iter_i(VALUE str, VALUE memop) return rb_yield(str); } -static VALUE wrap_each(struct clogger *c) +static VALUE wrap_close(struct clogger *c) { - c->body_bytes_sent = 0; - rb_iterate(rb_each, c->body, body_iter_i, (VALUE)&c->body_bytes_sent); - - return c->body; + if (rb_respond_to(c->body, close_id)) + return rb_funcall(c->body, close_id, 0); + return Qnil; } /** @@ -659,8 +658,10 @@ static VALUE clogger_each(VALUE self) struct clogger *c = clogger_get(self); rb_need_block(); + c->body_bytes_sent = 0; + rb_iterate(rb_each, c->body, body_iter_i, (VALUE)&c->body_bytes_sent); - return rb_ensure(wrap_each, (VALUE)c, cwrite, (VALUE)c); + return self; } /** @@ -675,9 +676,7 @@ static VALUE clogger_close(VALUE self) { struct clogger *c = clogger_get(self); - if (rb_respond_to(c->body, close_id)) - return rb_funcall(c->body, close_id, 0); - return Qnil; + return rb_ensure(wrap_close, (VALUE)c, cwrite, (VALUE)c); } /* :nodoc: */ -- cgit v1.2.3-24-ge0c7