6324c7d2741d58f2e59f7003db99547bf955e980
3 require 'rack/content_length'
8 def self.run(app
, options
={})
9 file
= options
[:File] and STDIN.reopen(UNIXServer
.new(file
))
10 port
= options
[:Port] and STDIN.reopen(TCPServer
.new(port
))
16 module ProperStream
# :nodoc:
17 def each
# This is missing by default.
25 super || "" # Empty string on EOF.
32 def self.serve(request
, app
)
33 app
= Rack
::ContentLength.new(app
)
36 env.delete
"HTTP_CONTENT_LENGTH"
38 request
.in.extend ProperStream
40 env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
42 env.update({"rack.version" => [0,1],
43 "rack.input" => request
.in,
44 "rack.errors" => request
.err
,
46 "rack.multithread" => false,
47 "rack.multiprocess" => true,
48 "rack.run_once" => false,
50 "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
53 env["QUERY_STRING"] ||= ""
54 env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
55 env["REQUEST_PATH"] ||= "/"
56 env.delete
"PATH_INFO" if env["PATH_INFO"] == ""
57 env.delete
"CONTENT_TYPE" if env["CONTENT_TYPE"] == ""
58 env.delete
"CONTENT_LENGTH" if env["CONTENT_LENGTH"] == ""
60 status
, headers
, body
= app
.call(env)
62 send_headers request
.out
, status
, headers
63 send_body request
.out
, body
65 body
.close
if body
.respond_to
? :close
70 def self.send_headers(out
, status
, headers
)
71 out
.print
"Status: #{status}\r\n"
72 headers
.each
{ |k
, vs
|
73 vs
.split("\n").each
{ |v
|
74 out
.print
"#{k}: #{v}\r\n"
81 def self.send_body(out
, body
)