Project

General

Profile

RE: Cannot login after upgrade ยป mongrel.rb

Etienne Massip, 2011-12-20 11:33

 
1
if ['2.3.8', '2.3.9', '2.3.10', '2.3.11', '2.3.12', '2.3.14'].include?(Rails.version) && Gem.available?('mongrel', '~>1.1.5') && self.class.const_defined?(:Mongrel)
2
  
3
  # Pulled right from latest rack. Old looked like this in 1.1.0 version.
4
  # 
5
  # def [](k)
6
  #   super(@names[k] ||= @names[k.downcase])
7
  # end
8
  # 
9
  module Rack
10
    module Utils
11
      class HeaderHash < Hash
12
        def [](k)
13
          super(@names[k]) if @names[k]
14
          super(@names[k.downcase])
15
        end
16
      end
17
    end
18
  end
19
  
20
  # Code pulled from the ticket above.
21
  # 
22
  class Mongrel::CGIWrapper
23
    def header_with_rails_fix(options = 'text/html')
24
      @head['cookie'] = options.delete('cookie').flatten.map { |v| v.sub(/^\n/,'') } if options.class != String and options['cookie']
25
      header_without_rails_fix(options)
26
    end
27
    alias_method_chain :header, :rails_fix
28
  end
29
  
30
  # Pulled right from 2.3.8 ActionPack. Simple diff was
31
  # 
32
  # if headers.include?('Set-Cookie')
33
  #   headers['cookie'] = headers.delete('Set-Cookie').split("\n")
34
  # end
35
  # 
36
  # to 
37
  # 
38
  # if headers['Set-Cookie']
39
  #   headers['cookie'] = headers.delete('Set-Cookie').split("\n")
40
  # end
41
  #       
42
  module ActionController
43
    class CGIHandler
44
      def self.dispatch_cgi(app, cgi, out = $stdout)
45
        env = cgi.__send__(:env_table)
46
        env.delete "HTTP_CONTENT_LENGTH"
47
        cgi.stdinput.extend ProperStream
48
        env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
49
        env.update({
50
          "rack.version" => [0,1],
51
          "rack.input" => cgi.stdinput,
52
          "rack.errors" => $stderr,
53
          "rack.multithread" => false,
54
          "rack.multiprocess" => true,
55
          "rack.run_once" => false,
56
          "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
57
        })
58
        env["QUERY_STRING"] ||= ""
59
        env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
60
        env["REQUEST_PATH"] ||= "/"
61
        env.delete "PATH_INFO" if env["PATH_INFO"] == ""
62
        status, headers, body = app.call(env)
63
        begin
64
          out.binmode if out.respond_to?(:binmode)
65
          out.sync = false if out.respond_to?(:sync=)
66
          headers['Status'] = status.to_s
67
          if headers['Set-Cookie']
68
            headers['cookie'] = headers.delete('Set-Cookie').split("\n")
69
          end
70
          out.write(cgi.header(headers))
71
          body.each { |part|
72
            out.write part
73
            out.flush if out.respond_to?(:flush)
74
          }
75
        ensure
76
          body.close if body.respond_to?(:close)
77
        end
78
      end
79
    end
80
  end
81
  
82
end
    (1-1/1)