From 4efbf8fc3f458fc3e0d84db938afb415661089f0 Mon Sep 17 00:00:00 2001 From: Shin-ichiro OGAWA Date: Mon, 26 Sep 2011 17:11:23 +0900 Subject: [PATCH] Not applying Filter/ParamsFilter for smart-phones --- lib/jpmobile/mobile/abstract_mobile.rb | 10 ++++++++++ lib/jpmobile/mobile/iphone.rb | 10 ++++++++++ lib/jpmobile/mobile/smart_phone.rb | 10 ++++++++++ lib/jpmobile/rack/filter.rb | 2 +- lib/jpmobile/rack/params_filter.rb | 2 +- 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/jpmobile/mobile/abstract_mobile.rb b/lib/jpmobile/mobile/abstract_mobile.rb index 363eef3a..21e7ec80 100644 --- a/lib/jpmobile/mobile/abstract_mobile.rb +++ b/lib/jpmobile/mobile/abstract_mobile.rb @@ -58,6 +58,16 @@ def smart_phone? false end + # Jpmobile::Rack::Filter を適用するかどうか + def apply_filter? + true + end + + # Jpmobile::Rack::ParamsFilter を適用するかどうか + def apply_params_filter? + true + end + # エンコーディング変換用 def to_internal(str) str diff --git a/lib/jpmobile/mobile/iphone.rb b/lib/jpmobile/mobile/iphone.rb index 0febf2f4..aa5d2e2d 100644 --- a/lib/jpmobile/mobile/iphone.rb +++ b/lib/jpmobile/mobile/iphone.rb @@ -7,6 +7,16 @@ class Iphone < SmartPhone # 対応するUser-Agentの正規表現 USER_AGENT_REGEXP = /iPhone/ + # Jpmobile::Rack::Filter を適用する + def apply_filter? + true + end + + # Jpmobile::Rack::ParamsFilter を適用する + def apply_params_filter? + true + end + # 文字コード変換 def to_internal(str) # 絵文字を数値参照に変換 diff --git a/lib/jpmobile/mobile/smart_phone.rb b/lib/jpmobile/mobile/smart_phone.rb index 593d6dca..11e84166 100644 --- a/lib/jpmobile/mobile/smart_phone.rb +++ b/lib/jpmobile/mobile/smart_phone.rb @@ -17,5 +17,15 @@ def supports_cookie? def smart_phone? true end + + # Jpmobile::Rack::Filter は適用しない + def apply_filter? + false + end + + # Jpmobile::Rack::ParamsFilter は適用しない + def apply_params_filter? + false + end end end diff --git a/lib/jpmobile/rack/filter.rb b/lib/jpmobile/rack/filter.rb index 757af8db..479de2f8 100644 --- a/lib/jpmobile/rack/filter.rb +++ b/lib/jpmobile/rack/filter.rb @@ -15,7 +15,7 @@ def call(env) status, env, response = @app.call(env) - if mobile and env['Content-Type'] =~ %r!text/html|application/xhtml\+xml! + if mobile and mobile.apply_filter? and env['Content-Type'] =~ %r!text/html|application/xhtml\+xml! type, charset = env['Content-Type'].split(/;\s*charset=/) body = response_to_body(response) diff --git a/lib/jpmobile/rack/params_filter.rb b/lib/jpmobile/rack/params_filter.rb index db0c6a6d..b6ffbdae 100644 --- a/lib/jpmobile/rack/params_filter.rb +++ b/lib/jpmobile/rack/params_filter.rb @@ -9,7 +9,7 @@ def initialize(app) def call(env) # 入力 - if @mobile = env['rack.jpmobile'] + if @mobile = env['rack.jpmobile'] and @mobile.apply_params_filter? # パラメータをkey, valueに分解 # form_params if env['REQUEST_METHOD'] == 'POST'