Class Rack::Forwarder
In: lib/rack/forward.rb
Parent: Object

Methods

call   new  

Public Class methods

[Source]

    # File lib/rack/forward.rb, line 12
12:     def initialize(host, port=80)
13:       @host, @port = host, port
14:     end

Public Instance methods

[Source]

    # File lib/rack/forward.rb, line 16
16:     def call(env)
17:       rackreq = Rack::Request.new(env)
18: 
19:       headers = Rack::Utils::HeaderHash.new
20:       env.each { |key, value|
21:         if key =~ /HTTP_(.*)/
22:           headers[$1] = value
23:         end
24:       }
25: 
26:       res = Net::HTTP.start(@host, @port) { |http|
27:         m = rackreq.request_method
28:         case m
29:         when "GET", "HEAD", "DELETE", "OPTIONS", "TRACE"
30:           req = Net::HTTP.const_get(m.capitalize).new(rackreq.fullpath, headers)
31:         when "PUT", "POST"
32:           req = Net::HTTP.const_get(m.capitalize).new(rackreq.fullpath, headers)
33:           req.body_stream = rackreq.body
34:         else
35:           raise "method not supported: #{method}"
36:         end
37: 
38:         http.request(req)
39:       }
40: 
41:       [res.code, Rack::Utils::HeaderHash.new(res.to_hash), [res.body]]
42:     end

[Validate]