Class: Rack::OverrideUserAgent
- Inherits:
-
Object
- Object
- Rack::OverrideUserAgent
- Defined in:
- lib/rack/override_user_agent.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ OverrideUserAgent
constructor
A new instance of OverrideUserAgent.
Constructor Details
#initialize(app, options = {}) ⇒ OverrideUserAgent
Returns a new instance of OverrideUserAgent.
3 4 5 6 7 8 |
# File 'lib/rack/override_user_agent.rb', line 3 def initialize(app, = {}) @app = app @params_key = [:params_key] || 'rack-override-user-agent' @params_key = @params_key.to_s @preset_ua = [:preset_ua] || {} end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rack/override_user_agent.rb', line 10 def call(env) request = Rack::Request.new(env) = nil if ua = request.params["#{@params_key}-rm"] = :delete elsif ua = request.params[@params_key] ua = @preset_ua[ua.to_sym] || @preset_ua[ua.to_s] || ua env['HTTP_USER_AGENT'] = ua = :set elsif ua = request.[@params_key] env['HTTP_USER_AGENT'] = ua end status, headers, body = @app.call(env) response = Rack::Response.new response.status = status headers.map {|key, value| response[key] = value} response.body = body case when :delete response.(@params_key, {:path => '/'}) when :set response.(@params_key, {:value => ua, :path => '/'}) end response.finish end |