Skip to content

Instantly share code, notes, and snippets.

@PatrickLef
Created March 10, 2011 08:29
Show Gist options
  • Save PatrickLef/863752 to your computer and use it in GitHub Desktop.
Save PatrickLef/863752 to your computer and use it in GitHub Desktop.
##
## SERVER (config.ru)
## Start with: thin start -V -R config.ru
app = proc do |env|
[
200,
{
'Content-Type' => 'text/html',
'Content-Length' => '2'
},
['hi']
]
end
run app
##
## CLIENT
##
require 'rubygems'
require 'eventmachine'
gem 'em-http-request', "1.0.0.beta.1"
require 'em-http-request'
EventMachine.run do
# Mongrel doesn't support pipelined requests - bah!
conn = EventMachine::HttpRequest.new('http://127.0.0.1:4567/', :keepalive => true)
pipe1 = conn.get(:keepalive => true, :head => {'Connection' => 'keep-alive'})
pipe2 = conn.get
processed = 0
stop = proc { EM.stop if processed == 2}
pipe1.errback { p pipe1 }
pipe1.callback {
processed += 1
p pipe1.response_header.status
stop.call
}
pipe2.errback { p pipe2 }
pipe2.callback {
processed += 1
p pipe2.response_header.status
stop.call
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment