Skip to content

Instantly share code, notes, and snippets.

@tomas-stefano
Created November 28, 2010 15:00
Show Gist options
  • Select an option

  • Save tomas-stefano/718996 to your computer and use it in GitHub Desktop.

Select an option

Save tomas-stefano/718996 to your computer and use it in GitHub Desktop.
Http Headers with EventMachine
require 'rubygems'
require 'eventmachine'
module HttpHeaders
def post_init
send_data "GET /\r\n\r\n"
@data = ""
end
def receive_data(data)
@data << data
end
def unbind
if @data =~ /[\n][\r]*[\n]/m
$`.each { |line| puts ">>> #{line}" }
end
EventMachine.stop_event_loop
end
end
EventMachine.run do
EventMachine.connect ARGV[0], 80, HttpHeaders
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment