From 82ea9b442a9edaae6dc3b06a5c61035b2c2924c9 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 19 Dec 2010 18:47:23 +0000 Subject: http: delay clearing env on HttpParser#next? This allows apps/middlewares on Rainbows! that rely on env in the response_body#close to hold onto the env. --- ext/unicorn_http/unicorn_http.rl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl index 6cc2958..42fcf1d 100644 --- a/ext/unicorn_http/unicorn_http.rl +++ b/ext/unicorn_http/unicorn_http.rl @@ -21,6 +21,7 @@ #define UH_FL_REQEOF 0x40 #define UH_FL_KAVERSION 0x80 #define UH_FL_HASHEADER 0x100 +#define UH_FL_TO_CLEAR 0x200 /* all of these flags need to be set for keepalive to be supported */ #define UH_FL_KEEPALIVE (UH_FL_KAVERSION | UH_FL_REQEOF | UH_FL_HASHEADER) @@ -537,6 +538,11 @@ static VALUE HttpParser_parse(VALUE self) struct http_parser *hp = data_get(self); VALUE data = hp->buf; + if (hp->flags == UH_FL_TO_CLEAR) { + hp->flags = 0; + rb_funcall(hp->env, id_clear, 0); + } + http_parser_execute(hp, RSTRING_PTR(data), RSTRING_LEN(data)); VALIDATE_MAX_LENGTH(hp->offset, HEADER); @@ -630,7 +636,7 @@ static VALUE HttpParser_next(VALUE self) if (HP_FL_ALL(hp, KEEPALIVE)) { http_parser_init(hp); - rb_funcall(hp->env, id_clear, 0); + hp->flags = UH_FL_TO_CLEAR; return Qtrue; } return Qfalse; -- cgit v1.2.3-24-ge0c7