[PATCH] env["hack.io"] for Fiber*, Revactor, Thread* models
Eric Wong
normalperson at yhbt.net
Fri Dec 11 06:59:05 EST 2009
This exposes a client IO object directly to the underlying
application.
---
In case you already have an installation and just want to patch that,
this is the patch I made for Rainbows! that exposes the ability to
be used with LMGTWTY
lib/rainbows/base.rb | 1 +
lib/rainbows/const.rb | 6 ++++++
lib/rainbows/fiber/base.rb | 1 +
lib/rainbows/revactor.rb | 1 +
4 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb
index 424b43b..a735b82 100644
--- a/lib/rainbows/base.rb
+++ b/lib/rainbows/base.rb
@@ -43,6 +43,7 @@ module Rainbows
buf << client.readpartial(CHUNK_SIZE)
end
+ env[CLIENT_IO] = client
env[RACK_INPUT] = 0 == hp.content_length ?
HttpRequest::NULL_IO :
Unicorn::TeeInput.new(client, env, hp, buf)
diff --git a/lib/rainbows/const.rb b/lib/rainbows/const.rb
index 69e58aa..900c9d9 100644
--- a/lib/rainbows/const.rb
+++ b/lib/rainbows/const.rb
@@ -19,5 +19,11 @@ module Rainbows
CONN_ALIVE = "Connection: keep-alive\r\n"
LOCALHOST = "127.0.0.1"
+ # client IO object that supports reading and writing directly
+ # without filtering it through the HTTP chunk parser.
+ # Maybe we can get this renamed to "rack.io" if it becomes part
+ # of the official spec, but for now it is "hack.io"
+ CLIENT_IO = "hack.io".freeze
+
end
end
diff --git a/lib/rainbows/fiber/base.rb b/lib/rainbows/fiber/base.rb
index 129448c..995b4af 100644
--- a/lib/rainbows/fiber/base.rb
+++ b/lib/rainbows/fiber/base.rb
@@ -82,6 +82,7 @@ module Rainbows
buf << (client.read_timeout or return)
end
+ env[CLIENT_IO] = client
env[RACK_INPUT] = 0 == hp.content_length ?
HttpRequest::NULL_IO : TeeInput.new(client, env, hp, buf)
env[REMOTE_ADDR] = remote_addr
diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb
index b647d48..ff0e429 100644
--- a/lib/rainbows/revactor.rb
+++ b/lib/rainbows/revactor.rb
@@ -49,6 +49,7 @@ module Rainbows
buf << client.read(*rd_args)
end
+ env[Const::CLIENT_IO] = client
env[Const::RACK_INPUT] = 0 == hp.content_length ?
HttpRequest::NULL_IO :
Rainbows::Revactor::TeeInput.new(client, env, hp, buf)
--
Eric Wong
More information about the rainbows-talk
mailing list