Class: ActiveRecordProxyAdapters::Middleware
- Inherits:
-
Object
- Object
- ActiveRecordProxyAdapters::Middleware
- Extended by:
- ActiveRecordProxyAdapters::Mixin::Configuration
- Defined in:
- lib/active_record_proxy_adapters/middleware.rb
Overview
rubocop:disable Style/Documentation
Constant Summary collapse
- COOKIE_NAME =
"arpa_context"- COOKIE_BUFFER =
5.seconds.freeze
- DEFAULT_COOKIE_OPTIONS =
{ path: "/", http_only: true }.freeze
- COOKIE_READER =
lambda do |rack_env| rack_request = Rack::Request.new(rack_env) = rack_request.[COOKIE_NAME] JSON.parse( || "{}") rescue JSON::ParserError {} end.freeze
- COOKIE_WRITER =
lambda do |headers, , | = DEFAULT_COOKIE_OPTIONS.merge() max_value = .values.max || 0 then_time = Time.at(max_value).utc expires = then_time + proxy_delay(.key(max_value)) + COOKIE_BUFFER max_age = expires - then_time [:expires] = expires [:max_age] = max_age [:value] = .to_json Rack::Utils.(headers, COOKIE_NAME, ) end.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, cookie_options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Methods included from ActiveRecordProxyAdapters::Mixin::Configuration
cache_key_for, cache_store, checkout_timeout, context_store, log_subscriber_prefix, logger, proxy_delay, regexp_timeout_strategy
Methods included from Contextualizer
current_context, current_context=
Constructor Details
#initialize(app, cookie_options = {}) ⇒ Middleware
Returns a new instance of Middleware.
46 47 48 49 |
# File 'lib/active_record_proxy_adapters/middleware.rb', line 46 def initialize(app, = {}) @app = app @cookie_options = end |
Instance Method Details
#call(env) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/active_record_proxy_adapters/middleware.rb', line 51 def call(env) return @app.call(env) if ignore_request?(env) self.current_context = context_store.new(COOKIE_READER.call(env)) status, headers, body = @app.call(env) (headers) [status, headers, body] end |