Skip to content

Commit

Permalink
yield to run block right before accepting connections
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Jun 23, 2010
1 parent 66d35ee commit 0385bcc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions kidgloves.rb
Expand Up @@ -49,8 +49,8 @@ class KidGloves
505 => 'HTTP Version Not Supported'
}

def self.run(app, options=nil)
new(app).listen
def self.run(app, options=nil, &block)
new(app).listen(&block)
end

def initialize(app)
Expand All @@ -61,6 +61,8 @@ def listen
log 'Starting server on 0.0.0.0:8089'
server = TCPServer.new('0.0.0.0', 8089)

yield server if block_given?

loop do
socket = server.accept
socket.sync = true
Expand Down Expand Up @@ -136,7 +138,7 @@ def process_request(request, input_body, socket)
vs.split("\n").each { |v| socket.write("#{k}: #{v}\r\n")}
end
socket.write("\r\n")
body.each {|s| socket.write(s)}
body.each { |s| socket.write(s) }
ensure
body.close if body.respond_to? :close
end
Expand Down

0 comments on commit 0385bcc

Please sign in to comment.