Class: ShopifyApp::SameSiteCookieMiddleware
- Inherits:
-
Object
- Object
- ShopifyApp::SameSiteCookieMiddleware
- Defined in:
- lib/ruby_shopify_app/middleware/same_site_cookie_middleware.rb
Constant Summary collapse
- COOKIE_SEPARATOR =
"\n"
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ SameSiteCookieMiddleware
constructor
A new instance of SameSiteCookieMiddleware.
Constructor Details
#initialize(app) ⇒ SameSiteCookieMiddleware
Returns a new instance of SameSiteCookieMiddleware.
6 7 8 |
# File 'lib/ruby_shopify_app/middleware/same_site_cookie_middleware.rb', line 6 def initialize(app) @app = app 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 |
# File 'lib/ruby_shopify_app/middleware/same_site_cookie_middleware.rb', line 10 def call(env) status, headers, body = @app.call(env) user_agent = env['HTTP_USER_AGENT'] if headers && headers['Set-Cookie'] && BrowserSniffer.new(user_agent).same_site_none_compatible? && ShopifyApp.configuration.enable_same_site_none && Rack::Request.new(env).ssl? = headers['Set-Cookie'] .split(COOKIE_SEPARATOR) .compact .map do || << '; Secure' unless =~ /;\s*secure/i << '; SameSite=None' if ShopifyApp.configuration. end headers['Set-Cookie'] = .join(COOKIE_SEPARATOR) end [status, headers, body] end |