-
Website
http://macournoyer.com -
Original page
http://macournoyer.com/blog/2009/06/04/pusher-and-async-with-thin/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
justinwr
1 comment · 1 points
-
samnardoni
1 comment · 1 points
-
Magnus Holm
1 comment · 1 points
-
Dan Simard
2 comments · 4 points
-
raggi
4 comments · 2 points
-
-
Popular Threads
There is a typo:
EM.next_tick dp
I fixed the typo.
Mind if I use your DeferrableBody code in http://github.com/collin/orbited-ruby
Of course fell free to use DeferrableBody. I stole it from raggi initially.
:) Awesome. This post and the resources linked to within have proven invaluable :)
http://github.com/collin/orbited-ruby/tree/master
Have it almost working with the existing Orbited client code :)
Anybody have a notion of when we can expect to have a unified asynchronous callback api in Rack? Thin is nice, but it'd be even nicer if more rack servers could be expected to run this stuff.
http://gist.github.com/187018
I'm using rack to build an http proxy. The proxy works rougly like this:
Request comes in.
Open Socket to the host and port of the Request.
Replay entire Request Body onto Socket.
As data comes back over Socket, write to Request's Async Chunk Callback.
Any thoughts about better ways to do this?
With my proxy I want to play the "remote" response back directly over the "local" request.
My rack handler looks like this:
def call(env)
request = Rack::Request.new
# using a modified DeferrableBody so I can control the callback used.
socket = EM.connect request.host, request.port, RequestProxy, DeferrableBody(@env['async.chunk_callback'])
socket.send_data @env['http.request_body'] # plain, unparsed FULL http request
end
class TCPSocketProxy < EventMachine::Connection
def initialize socket # socket is the async chunk callback
@socket = socket
end
def recieve_data data
@socket.call data
#
EM.next_tick { close_conncetion } if finished?
end
def unbind
@socket.succeed
end
def finished?
# I have implementations of these, but need to redo them with a proper HTTPResponse parser
return false unless headers_recieved?
return true if not_modified?
return false unless content_length
return true if body_length = content_length
end
end