From 7f3ec4105ba629d2229f07e06ea2d475824bac84 Mon Sep 17 00:00:00 2001 From: Mal Curtis Date: Tue, 13 Aug 2013 13:56:02 +1200 Subject: [PATCH 1/7] Only intercept font asset preflight requests Don't assume this is the only middleware handling preflights. --- lib/font_assets/middleware.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/font_assets/middleware.rb b/lib/font_assets/middleware.rb index d4639b4..871bcd4 100644 --- a/lib/font_assets/middleware.rb +++ b/lib/font_assets/middleware.rb @@ -24,7 +24,11 @@ def call(env) @ssl_request = Rack::Request.new(env).scheme == "https" # intercept the "preflight" request if env["REQUEST_METHOD"] == "OPTIONS" - return [200, access_control_headers, []] + if ext = extension(env["PATH_INFO"]) and font_asset?(ext) + return [200, access_control_headers, []] + else + return @app.call(env) + end else code, headers, body = @app.call(env) set_headers! headers, body, env["PATH_INFO"] From a83ea5c0f5b865f89aeb582c285dccdf4fa939f3 Mon Sep 17 00:00:00 2001 From: Mal Curtis Date: Wed, 20 Nov 2013 20:04:14 +1300 Subject: [PATCH 2/7] Add in a middleware insert target option --- lib/font_assets/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/font_assets/railtie.rb b/lib/font_assets/railtie.rb index efc801d..0a5545f 100644 --- a/lib/font_assets/railtie.rb +++ b/lib/font_assets/railtie.rb @@ -8,7 +8,7 @@ class Railtie < Rails::Railtie config.font_assets.origin ||= "*" config.font_assets.options ||= { allow_ssl: true } - insert_target = if defined?(ActionDispatch::Static) + config.font_assets.insert_target ||= if defined?(ActionDispatch::Static) 'ActionDispatch::Static' else 'Rack::Runtime' From 51eda2e29f2eb2831da809ca0290a8e39414a54e Mon Sep 17 00:00:00 2001 From: Mal Curtis Date: Wed, 20 Nov 2013 20:11:55 +1300 Subject: [PATCH 3/7] Use the configured insert_target --- lib/font_assets/railtie.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/font_assets/railtie.rb b/lib/font_assets/railtie.rb index 0a5545f..0c3c3e1 100644 --- a/lib/font_assets/railtie.rb +++ b/lib/font_assets/railtie.rb @@ -14,7 +14,10 @@ class Railtie < Rails::Railtie 'Rack::Runtime' end - app.middleware.insert_before insert_target, FontAssets::Middleware, config.font_assets.origin, config.font_assets.options + app.middleware.insert_before config.font_assets.insert_target, + FontAssets::Middleware, + config.font_assets.origin, + config.font_assets.options end end end From 29b63b3b6bb9cadfc9a3c584088ae7bee18156c7 Mon Sep 17 00:00:00 2001 From: Mal Curtis Date: Fri, 22 Nov 2013 14:01:49 +1300 Subject: [PATCH 4/7] Default #extension param path to '' --- lib/font_assets/middleware.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/font_assets/middleware.rb b/lib/font_assets/middleware.rb index 871bcd4..5584180 100644 --- a/lib/font_assets/middleware.rb +++ b/lib/font_assets/middleware.rb @@ -61,7 +61,7 @@ def allow_ssl? @options[:allow_ssl] end - def extension(path) + def extension(path='') "." + path.split("?").first.split(".").last end From b54017275f99a2d9403351ad74000e47b67a526f Mon Sep 17 00:00:00 2001 From: Mal Curtis Date: Fri, 22 Nov 2013 14:36:12 +1300 Subject: [PATCH 5/7] #extension checks for nil path --- lib/font_assets/middleware.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/font_assets/middleware.rb b/lib/font_assets/middleware.rb index 5584180..c54403f 100644 --- a/lib/font_assets/middleware.rb +++ b/lib/font_assets/middleware.rb @@ -61,7 +61,8 @@ def allow_ssl? @options[:allow_ssl] end - def extension(path='') + def extension(path) + path ||= '' "." + path.split("?").first.split(".").last end From 650028c46a99cfba00870ea0142f113a76a85e0e Mon Sep 17 00:00:00 2001 From: Mal Curtis Date: Sat, 30 Nov 2013 11:24:49 +1300 Subject: [PATCH 6/7] Default path to / --- lib/font_assets/middleware.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/font_assets/middleware.rb b/lib/font_assets/middleware.rb index c54403f..c8bf376 100644 --- a/lib/font_assets/middleware.rb +++ b/lib/font_assets/middleware.rb @@ -62,7 +62,7 @@ def allow_ssl? end def extension(path) - path ||= '' + path ||= '/' "." + path.split("?").first.split(".").last end From 5d5d7b66c0a1bd0468f5a305a9dec09f5bc59e4d Mon Sep 17 00:00:00 2001 From: Mal Curtis Date: Sat, 30 Nov 2013 22:07:24 +1300 Subject: [PATCH 7/7] Handle string exceptions in #extension --- lib/font_assets/middleware.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/font_assets/middleware.rb b/lib/font_assets/middleware.rb index c8bf376..8620263 100644 --- a/lib/font_assets/middleware.rb +++ b/lib/font_assets/middleware.rb @@ -62,8 +62,9 @@ def allow_ssl? end def extension(path) - path ||= '/' "." + path.split("?").first.split(".").last + rescue + "." end def font_asset?(path)