diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-06-06 00:43:34 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-06-06 05:19:34 +0000 |
commit | bc1d1df38d7803ce9fdae05fc5129051eeed89e0 (patch) | |
tree | fda0e314119f27ed3ea4aa6848d653e2ff0070ed /ext | |
parent | e4c3548e8ff4c95c697b4a30699e6f655d60f188 (diff) | |
download | clogger-bc1d1df38d7803ce9fdae05fc5129051eeed89e0.tar.gz |
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.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/clogger_ext/clogger.c | 17 |
1 files changed, 8 insertions, 9 deletions
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: */ |