diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-11-06 10:30:44 +0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-11-06 10:30:44 +0800 |
commit | 60a9ec94f1f738f881e67f0a881c44c104f07c04 (patch) | |
tree | 0bbef83b7f08107326cf0fd91fd73aa58a85605d /ext/unicorn_http/unicorn_http.rl | |
parent | 7987e1a4001491f8a494f3926037f8cbee713263 (diff) | |
download | unicorn-60a9ec94f1f738f881e67f0a881c44c104f07c04.tar.gz |
An easy combination of the existing HttpParser#keepalive? and HttpParser#reset methods, this makes it easier to implement persistence.
Diffstat (limited to 'ext/unicorn_http/unicorn_http.rl')
-rw-r--r-- | ext/unicorn_http/unicorn_http.rl | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl index fb99f9c..147750a 100644 --- a/ext/unicorn_http/unicorn_http.rl +++ b/ext/unicorn_http/unicorn_http.rl @@ -619,6 +619,25 @@ static VALUE HttpParser_keepalive(VALUE self) /** * call-seq: + * parser.next? => true or false + * + * Exactly like HttpParser#keepalive?, except it will reset the internal + * parser state if it returns true. + */ +static VALUE HttpParser_next(VALUE self) +{ + struct http_parser *hp = data_get(self); + + if (HP_FL_ALL(hp, KEEPALIVE)) { + http_parser_init(hp); + rb_funcall(hp->env, id_clear, 0); + return Qtrue; + } + return Qfalse; +} + +/** + * call-seq: * parser.headers? => true or false * * This should be used to detect if a request has headers (and if @@ -736,6 +755,7 @@ void Init_unicorn_http(void) rb_define_method(cHttpParser, "body_eof?", HttpParser_body_eof, 0); rb_define_method(cHttpParser, "keepalive?", HttpParser_keepalive, 0); rb_define_method(cHttpParser, "headers?", HttpParser_has_headers, 0); + rb_define_method(cHttpParser, "next?", HttpParser_next, 0); rb_define_method(cHttpParser, "buf", HttpParser_buf, 0); rb_define_method(cHttpParser, "env", HttpParser_env, 0); |