class Rack::Iphone
Constants
- CODE
- COOKIE
Public Class Methods
new(app)
click to toggle source
# File lib/rack_iphone.rb, line 48 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack_iphone.rb, line 52 def call(env) if iphone_web_app?(env) if new_session?(env) [200,{'Content-Length' => code(true).length.to_s, 'Content-Type' => 'text/html'}, code(true)] else status, headers, body = @app.call(env) # Put in patch code ## ## request = Rack::Request.new(env) response = Rack::Response.new([], status, headers) cookie = String.new request.cookies.each_pair do |key,value| cookie += "#{key}=#{value};" end body.each do |part| part.gsub!(/<\/head>/, "#{set_cookie(cookie)}</head>") response.write(part) end response.finish end else @app.call(env) end end
Protected Instance Methods
code(resend=false)
click to toggle source
# File lib/rack_iphone.rb, line 81 def code(resend=false) regex = "_session_id" regex = Rails.configuration.session_options[:key] if Rails.configuration.session_store.name == "ActionDispatch::Session::CookieStore" CODE.gsub('{{RESEND}}', resend.to_s).gsub('{{REGEX}}',regex.to_s) end
iphone_web_app?(env)
click to toggle source
# File lib/rack_iphone.rb, line 100 def iphone_web_app?(env) if env['HTTP_USER_AGENT'] env['HTTP_USER_AGENT'] =~ /WebKit.*Mobile/ && !(env['HTTP_USER_AGENT'] =~ /Safari/) end end
new_session?(env)
click to toggle source
# File lib/rack_iphone.rb, line 91 def new_session?(env) request = Rack::Request.new(env) if request.cookies['_cookieset_'].nil? true else false end end