about summary refs log tree commit homepage
path: root/ext
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-19 18:47:23 +0000
committerEric Wong <normalperson@yhbt.net>2010-12-19 23:19:25 +0000
commit82ea9b442a9edaae6dc3b06a5c61035b2c2924c9 (patch)
tree04b7e7e15db51a0830de7c9fc1e6ed5725d509af /ext
parent39f264173717287eda70910e7a24fbafd21a4a7e (diff)
downloadunicorn-82ea9b442a9edaae6dc3b06a5c61035b2c2924c9.tar.gz
This allows apps/middlewares on Rainbows! that rely on env in
the response_body#close to hold onto the env.
Diffstat (limited to 'ext')
-rw-r--r--ext/unicorn_http/unicorn_http.rl8
1 files changed, 7 insertions, 1 deletions
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;