add valid_cookie? method to HTTP::Cookie

master
Kanezoh 2021-08-06 16:40:52 +09:00
parent b67d20b157
commit f0afbf2c5f
1 changed files with 9 additions and 1 deletions

View File

@ -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