def cookie.domain.of

bend-kit-http@0.38.2.0 · http.bend:2275

import bend-kit-http@0.38.2.0/http.bend as Http
import Base

2275# §5.7 steps 8–10: (domain, host-only), or None to ignore the cookie.
2276# ponytail: the public-suffix check knows single-label suffixes only (com, org, localhost). Multi-label
2277# ones (co.uk, github.io) need the publicsuffix.org list; ship it as data when a caller needs it.
2278def cookie.domain.of(+host: String, +d: String) -> Maybe<&1, String & Bool>:
2279  +suffix = Bool.and(Bool.not(String.is_empty(d)), Bool.not(String.contains(d, ".")))
2280  +d2 = Bool.pick(String, Bool.and(suffix, String.eq(d, host)), "", d)
2281  Bool.pick(Maybe<&1, String & Bool>, Bool.or(Bool.and(suffix, Bool.not(String.eq(d, host))), Bool.not(cookie.ascii(d))), None{},
2282    Bool.pick(Maybe<&1, String & Bool>, String.is_empty(d2), Some{(host, True{})},
2283      Bool.pick(Maybe<&1, String & Bool>, cookie.domain_match(host, d2), Some{(d2, False{})}, None{})))

Uses (14)

Used by (1)