Method: Nitro::Cgi.process
- Defined in:
- lib/nitro/cgi.rb
.process(server, cgi, inp, out) ⇒ Object
Process a CGI request. This is a general method reused by many adapters. – A CGI request is process-based so there is no need for Og connection cleanup. ++
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nitro/cgi.rb', line 31 def self.process(server, cgi, inp, out) context = Context.new(server) unless inp.respond_to?(:rewind) # The module Request#raw_body requires a rewind method, # so if the input stream doesn't have one, *cough* FCgi, # we convert it to a StringIO. inp = StringIO.new(inp.read.to_s) # if read returns nil, to_s makes it "" end context.in = inp context.headers = cgi.env #-- # gmosx: only handle nitro requests. #++ # gmosx: QUERY_STRING is sometimes not populated. if context.query_string.empty? and context.uri =~ /\?/ context.headers['QUERY_STRING'] = context.uri.split('?').last end Cgi.parse_params(context) Cgi.(context) context.render(context.path) out.print(Cgi.response_headers(context)) if context.out.is_a?(IO) begin while buf = context.out.read(4096) out.write(buf) end ensure context.out.close end else out.print(context.out) end $autoreload_dirty = false context.close end |