about summary refs log tree commit homepage
path: root/t/close-has-env.ru
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-27 20:25:39 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-28 17:12:28 -0800
commit3495d59763e6159975debf32728dc53fc41c5ea1 (patch)
tree949415250af66075cc9ca98040a85ddc2ad84380 /t/close-has-env.ru
parent53afe0b23fc67c5b25541cddbd68f905c649e756 (diff)
downloadrainbows-3495d59763e6159975debf32728dc53fc41c5ea1.tar.gz
Some middlewares require the Rack env to be preserved all
the way through to close, so we'll ensure all request models
preserve it.

We also need to better response body wrappers/proxies always get
fired properly when returning.  IO.copy_stream and "sendfile"
gem users could hit cases where wrappers did not fire properly.
Diffstat (limited to 't/close-has-env.ru')
-rw-r--r--t/close-has-env.ru65
1 files changed, 65 insertions, 0 deletions
diff --git a/t/close-has-env.ru b/t/close-has-env.ru
new file mode 100644
index 0000000..471f605
--- /dev/null
+++ b/t/close-has-env.ru
@@ -0,0 +1,65 @@
+#\ -E none
+use Rainbows::DevFdResponse
+class ClosablePipe < ::IO
+  attr_accessor :env
+
+  def self.new(env)
+    rv = popen "echo hello", "rb"
+    rv.env = env
+    rv
+  end
+
+  def close
+    super
+    $stdout.syswrite "path_info=#{@env['PATH_INFO']}\n"
+  end
+end
+
+class ClosableFile < ::File
+  attr_accessor :env
+  alias to_path path
+  def close
+    super
+    $stdout.syswrite "path_info=#{@env['PATH_INFO']}\n"
+  end
+end
+
+class Blob
+  def initialize(env)
+    @env = env
+  end
+
+  def each(&block)
+    yield "BLOB\n"
+  end
+
+  def close
+    $stdout.syswrite "path_info=#{@env['PATH_INFO']}\n"
+  end
+end
+
+run(lambda { |env|
+  case env["PATH_INFO"]
+  when %r{\A/pipe/}
+    [ 200,
+      [ %w(Content-Length 6), %w(Content-Type text/plain)],
+      ClosablePipe.new(env)
+    ]
+  when %r{\A/file/}
+    f = ClosableFile.open("env.ru", "rb")
+    f.env = env
+    [ 200, {
+      'X-Req-Path' => env["PATH_INFO"],
+      'Content-Length' => f.stat.size.to_s,
+      'Content-Type' => 'text/plain' },
+      f
+    ]
+  when %r{\A/blob/}
+    [ 200,
+      [%w(Content-Length 5), %w(Content-Type text/plain)],
+      Blob.new(env)
+    ]
+  else
+    [ 404, [%w(Content-Length 0), %w(Content-Type text/plain)], [] ]
+  end
+})