Permalink
Browse files

named the lib

  • Loading branch information...
schacon committed Apr 10, 2010
1 parent ab45484 commit 1acc419d4d6a9ce985db7be48c6349a0475975b5
Showing with 18 additions and 18 deletions.
  1. +11 −0 example.rb
  2. +7 −18 simple_rack.rb → kidgloves.rb
View
@@ -0,0 +1,11 @@
+require 'rubygems'
+require 'rack'
+require 'kidgloves'
+
+class HelloWorld
+ def call(env)
+ [200, {"Content-Type" => "text/html"}, ["Hello world!"]]
+ end
+end
+
+Rack::Handler::KidGloves.run HelloWorld.new
@@ -1,14 +1,9 @@
-require 'rubygems'
require 'socket'
require 'stringio'
-require 'rack'
-require 'rack/content_length'
-require 'rack/chunked'
-require 'pp'
module Rack
module Handler
- class DumbServer
+ class KidGloves
attr_accessor :app
StatusMessage = {
@@ -73,30 +68,33 @@ def listen
begin
req = {}
+
+ # parse the request line
request = socket.gets
method, path, version = request.split(" ")
req["REQUEST_METHOD"] = method
info, query = path.split("?")
req["PATH_INFO"] = info
req["QUERY_STRING"] = query
+
+ # parse the headers
while (line = socket.gets)
line.strip!
break if line.size == 0
key, val = line.split(": ")
req[key] = val
end
- pp req
+ # parse the body
body = ''
if (len = req['Content-Length']) && ["POST", "PUT"].member?(method)
body = socket.read(len)
end
+ # process the request
process_request(req, body, socket)
- puts "DONE"
ensure
- # no matter what we have to put this thread on the bad list
socket.close if not socket.closed?
end
end
@@ -146,12 +144,3 @@ def process_request(request, input_body, socket)
end
end
end
-
-
-class HelloWorld
- def call(env)
- [200, {"Content-Type" => "text/html"}, ["Hello world!"]]
- end
-end
-
-Rack::Handler::DumbServer.run HelloWorld.new

0 comments on commit 1acc419

Please sign in to comment.