lib/sitehub/forward_proxy.rb in sitehub-0.4.8 vs lib/sitehub/forward_proxy.rb in sitehub-0.4.9

- old
+ new

@@ -1,12 +1,14 @@ # rubocop:disable Metrics/ParameterLists class SiteHub class ForwardProxy - include Rules, Resolver + include Rules, Resolver, Equality - attr_reader :downstream_client, :sitehub_cookie_name, :sitehub_cookie_path, :id, :mapped_path, :mapped_url + attr_reader :downstream_client, :sitehub_cookie_name, :id, :sitehub_cookie_path, :mapped_path, :mapped_url + transient :downstream_client + def initialize(sitehub_cookie_path: nil, sitehub_cookie_name:, id:, rule: nil, mapped_path:, mapped_url:) @downstream_client = DownstreamClient.new @sitehub_cookie_path = sitehub_cookie_path @sitehub_cookie_name = sitehub_cookie_name @id = id @@ -17,27 +19,17 @@ def call(env) request = env[REQUEST] request.map(mapped_path, mapped_url) - response = downstream_client.call(request) - value = request.cookies[sitehub_cookie_name.to_s] || id - response.set_cookie(sitehub_cookie_name, path: resolve_sitehub_cookie_path(request), value: value) - response + downstream_client.call(request).tap do |response| + response.set_cookie(sitehub_cookie_name, + path: resolve_sitehub_cookie_path(request), + value: id) + end end def resolve_sitehub_cookie_path(request) sitehub_cookie_path || request.path - end - - def ==(other) - expected = [other.mapped_path, - other.mapped_url, - other.rule, - other.id, - other.sitehub_cookie_name, - other.sitehub_cookie_path] - - expected == [mapped_path, mapped_url, rule, id, sitehub_cookie_name, sitehub_cookie_path] end end end