Class: Rack::Client::Base
- Inherits:
-
Object
- Object
- Rack::Client::Base
- Extended by:
- Forwardable
- Defined in:
- lib/rack/client/adapter/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #build_env(request_method, url, headers = {}, body = nil) ⇒ Object
-
#initialize(app) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(app) ⇒ Base
Returns a new instance of Base.
8 9 10 |
# File 'lib/rack/client/adapter/base.rb', line 8 def initialize(app) @app = app end |
Instance Method Details
#build_env(request_method, url, headers = {}, body = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rack/client/adapter/base.rb', line 24 def build_env(request_method, url, headers = {}, body = nil) env = Headers.new(headers).to_env env.update 'REQUEST_METHOD' => request_method env['CONTENT_TYPE'] ||= 'application/x-www-form-urlencoded' uri = URI.parse(url) path_info = uri.path.empty? ? '/' : uri.path path_info += '?' + uri.query unless uri.query.nil? || uri.query.empty? env.update 'PATH_INFO' => path_info env.update 'REQUEST_URI' => uri.to_s env.update 'SERVER_NAME' => uri.host env.update 'SERVER_PORT' => uri.port env.update 'SCRIPT_NAME' => '' input = case body when nil then StringIO.new when String then StringIO.new(body) end env.update 'rack.input' => input env.update 'rack.errors' => StringIO.new env.update 'rack.url_scheme' => uri.scheme env.update 'HTTPS' => env["rack.url_scheme"] == "https" ? "on" : "off" env end |