Class: PHPRPC::SCGIProcessor

Inherits:
SCGI::Processor
  • Object
show all
Defined in:
lib/phprpc/scgi_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SCGIProcessor

Returns a new instance of SCGIProcessor.



39
40
41
42
43
44
45
46
47
# File 'lib/phprpc/scgi_server.rb', line 39

def initialize(options = {})
  @app = options[:app]
  if not options.key?(:logfile) then
    @log = Object.new
    def @log.info(*args); end
    def @log.error(*args); end
  end
  super(options)
end

Instance Method Details

#process_request(request, input_body, socket) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/phprpc/scgi_server.rb', line 49

def process_request(request, input_body, socket)
  env = {}.replace(request)
  env["REQUEST_PATH"], env["QUERY_STRING"] = env["REQUEST_URI"].split('?', 2)
  env["QUERY_STRING"] ||= ""
  env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
  env["SCRIPT_NAME"] = env["PATH_INFO"] = env["REQUEST_PATH"]
  env["rack.input"] = StringIO.new(input_body)
  env["rack.multithread"] = true # this variable only used for rack pool session on debug mode
  env["rack.url_scheme"] = ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
  status, headers, body = @app.call(env)
  socket.write("Status: #{status}\r\n")
  headers.each { |k, v| socket.write("#{k}: #{v}\r\n") }
  socket.write("\r\n")
  socket.write(body)
end