~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/actionpack/lib/action_controller/cgi_process.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'action_controller/cgi_ext'
2
 
 
3
 
module ActionController #:nodoc:
4
 
  class CGIHandler
5
 
    module ProperStream
6
 
      def each
7
 
        while line = gets
8
 
          yield line
9
 
        end
10
 
      end
11
 
 
12
 
      def read(*args)
13
 
        if args.empty?
14
 
          super || ""
15
 
        else
16
 
          super
17
 
        end
18
 
      end
19
 
    end
20
 
 
21
 
    def self.dispatch_cgi(app, cgi, out = $stdout)
22
 
      env = cgi.__send__(:env_table)
23
 
      env.delete "HTTP_CONTENT_LENGTH"
24
 
 
25
 
      cgi.stdinput.extend ProperStream
26
 
 
27
 
      env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
28
 
 
29
 
      env.update({
30
 
        "rack.version" => [0,1],
31
 
        "rack.input" => cgi.stdinput,
32
 
        "rack.errors" => $stderr,
33
 
        "rack.multithread" => false,
34
 
        "rack.multiprocess" => true,
35
 
        "rack.run_once" => false,
36
 
        "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
37
 
      })
38
 
 
39
 
      env["QUERY_STRING"] ||= ""
40
 
      env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
41
 
      env["REQUEST_PATH"] ||= "/"
42
 
      env.delete "PATH_INFO" if env["PATH_INFO"] == ""
43
 
 
44
 
      status, headers, body = app.call(env)
45
 
      begin
46
 
        out.binmode if out.respond_to?(:binmode)
47
 
        out.sync = false if out.respond_to?(:sync=)
48
 
 
49
 
        headers['Status'] = status.to_s
50
 
 
51
 
        if headers.include?('Set-Cookie')
52
 
          headers['cookie'] = headers.delete('Set-Cookie').split("\n")
53
 
        end
54
 
 
55
 
        out.write(cgi.header(headers))
56
 
 
57
 
        body.each { |part|
58
 
          out.write part
59
 
          out.flush if out.respond_to?(:flush)
60
 
        }
61
 
      ensure
62
 
        body.close if body.respond_to?(:close)
63
 
      end
64
 
    end
65
 
  end
66
 
 
67
 
  class CgiRequest #:nodoc:
68
 
    DEFAULT_SESSION_OPTIONS = {
69
 
      :database_manager  => nil,
70
 
      :prefix            => "ruby_sess.",
71
 
      :session_path      => "/",
72
 
      :session_key       => "_session_id",
73
 
      :cookie_only       => true,
74
 
      :session_http_only => true
75
 
    }
76
 
  end
77
 
end