Skip to content

Instantly share code, notes, and snippets.

@raggi
Created July 5, 2010 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raggi/464518 to your computer and use it in GitHub Desktop.
Save raggi/464518 to your computer and use it in GitHub Desktop.
require 'eventmachine'
class HTTP < EM::Connection
include EM::P::LineText2
RESPONSE = <<-PLAIN
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 12
Connection: keep-alive
Server: test 1.0.0 codename mgabyt
hello world
PLAIN
def self.start
EM.start_server '0.0.0.0', 3001, self
end
def initialize
@buffer = []
end
def receive_line(line)
@buffer << line
if @buffer.last.strip.empty?
@buffer.replace []
send_data RESPONSE
end
end
end
EM.run do
p $$
HTTP.start
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment