From f0afbf2c5fb795e6c31e009b2e8019a86173b4ee Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Fri, 6 Aug 2021 16:40:52 +0900 Subject: [PATCH] add valid_cookie? method to HTTP::Cookie --- src/mechanize/http/agent.cr | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mechanize/http/agent.cr b/src/mechanize/http/agent.cr index ae4039d..110ca70 100644 --- a/src/mechanize/http/agent.cr +++ b/src/mechanize/http/agent.cr @@ -131,7 +131,7 @@ module MechanizeCr host = uri.host valid_cookies = ::HTTP::Cookies.new request_cookies.each do |cookie| - valid_cookies << cookie if cookie.origin == host || (cookie.domain && host.try &.=~(/.*#{cookie.domain.try &.gsub(".", "\.")}$/)) + valid_cookies << cookie if cookie.valid_cookie?(host) end valid_cookies end @@ -156,4 +156,12 @@ class HTTP::Cookie @value = value @origin = origin end + + def valid_cookie?(host) + if domain + host.try &.=~(/.*#{domain.try &.gsub(".", "\.")}$/) + else + origin == host + end + end end