Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add LiteSpeed handler

Courtesy of Adrian Madrid <aemadrid@gmail.com>

darcs-hash:20070712090234-4fc50-3dc5b6a49905ae46fcbca91d29661305fefb61bf.gz
  • Loading branch information...
commit cdab8c7376131a9f11a5207a19c2138bbc5ffce1 1 parent ec8425c
@chneukirchen authored
Showing with 57 additions and 0 deletions.
  1. +4 −0 README
  2. +1 −0  lib/rack.rb
  3. +52 −0 lib/rack/handler/lsws.rb
View
4 README
@@ -110,6 +110,9 @@ at my site:
* Bug fixes in the Camping adapter.
* Removed Rails adapter, was too alpha.
+* XXX, 2007: Third public release 0.3.
+ * LiteSpeed handler, by Adrian Madrid.
+
== Contact
Please mail bugs, suggestions and patches to
@@ -124,6 +127,7 @@ You are also welcome to join the #rack channel on irc.freenode.net.
* Michael Fellinger, for the helpful discussion, bugfixes and a better
Rack::Request interface.
+* Adrian Madrid, for the LiteSpeed handler.
* Christoffer Sawicki, for the Rails adapter.
* Tim Fletcher, for the HTTP authentication code.
* Luc Heinrich for the Cookie sessions and the static file handler.
View
1  lib/rack.rb
@@ -81,6 +81,7 @@ module Handler
autoload :FastCGI, "rack/handler/fastcgi"
autoload :Mongrel, "rack/handler/mongrel"
autoload :WEBrick, "rack/handler/webrick"
+ autoload :LSWS, "rack/handler/lsws"
end
end
View
52 lib/rack/handler/lsws.rb
@@ -0,0 +1,52 @@
+require 'lsapi'
+#require 'cgi'
+module Rack
+ module Handler
+ class LSWS
+ def self.run(app, options=nil)
+ while LSAPI.accept != nil
+ serve app
+ end
+ end
+ def self.serve(app)
+ env = ENV.to_hash
+ env.delete "HTTP_CONTENT_LENGTH"
+ env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
+ env.update({"rack.version" => [0,1],
+ "rack.input" => STDIN,
+ "rack.errors" => STDERR,
+ "rack.multithread" => false,
+ "rack.multiprocess" => true,
+ "rack.run_once" => false,
+ "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
+ })
+ env["QUERY_STRING"] ||= ""
+ env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
+ env["REQUEST_PATH"] ||= "/"
+ status, headers, body = app.call(env)
+ begin
+ send_headers status, headers
+ send_body body
+ ensure
+ body.close if body.respond_to? :close
+ end
+ end
+ def self.send_headers(status, headers)
+ print "Status: #{status}\r\n"
+ headers.each { |k, vs|
+ vs.each { |v|
+ print "#{k}: #{v}\r\n"
+ }
+ }
+ print "\r\n"
+ STDOUT.flush
+ end
+ def self.send_body(body)
+ body.each { |part|
+ print part
+ STDOUT.flush
+ }
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.