Created
July 5, 2010 16:40
-
-
Save raggi/464518 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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