cookie.bend checks
raw source on the hub · import element-http@0.1.0.0/cookie.bend as Cookie
2 imports
import Base import element-asn1@0.1.0.0/der.bend as Der
Types
type Cookie source · line 16 · raw
Data
Cookie@name:String -> @value:String -> @domain:String -> @host_only:Bool -> @path:String -> @expires:U32 -> @secure:Bool -> @http_only:Bool -> @same_site:String -> Cookie
type D source · line 125 · raw
Data
What the date tokens say so far: time (seconds into the day), day, month, year, each with whether it was found.
D@tf:Bool -> @time:Nat -> @df:Bool -> @day:Nat -> @mf:Bool -> @month:Nat -> @yf:Bool -> @year:Nat -> D
type A source · line 238 · raw
Data
A@ef:Bool -> @exp:U32 -> @mf:Bool -> @neg:Bool -> @age:U32 -> @domain:String -> @path:String -> @secure:Bool -> @http_only:Bool -> @same_site:String -> A
Definitions
def rev_str source · line 24 · raw
@cs:List<&2, Char> -> String
def ltrim source · line 27 · raw
@s:String -> String
def trim source · line 34 · raw
@+s:String -> String
def cut_out source · line 39 · raw
@cut:Bool -> @+cur:List<&2, Char> -> @+out:List<&2, String> -> List<&2, String>
The pieces so far, with the current one closed at a cut (a pick reversed it at every char: quadratic in the pieces' length).
def split_go source · line 47 · raw
@s:String -> @+sep:Char -> @+cur:List<&2, Char> -> @+out:List<&2, String> -> List<&2, String>
Split at every sep.
def split source · line 55 · raw
@+s:String -> @+sep:Char -> List<&2, String>
def before source · line 58 · raw
@s:String -> @+c:Char -> String
def after source · line 65 · raw
@s:String -> @+c:Char -> String
def has source · line 72 · raw
@s:String -> @+c:Char -> Bool
def digits source · line 79 · raw
@s:String -> @+acc:Nat -> Nat
def digits32 source · line 87 · raw
@s:String -> @+acc:U32 -> U32
Decimal digits as U32, saturating (seconds stay U32 for the law checker).
def all_digits source · line 94 · raw
@s:String -> Bool
def lower source · line 101 · raw
@+s:String -> String
def date_tokens source · line 107 · raw
@s:String -> @+cur:List<&2, Char> -> @+out:List<&2, String> -> List<&2, String>
Tokens of a cookie-date: runs of letters, digits and ':'.
def month_of source · line 116 · raw
@+t:String -> Nat
def nth_s source · line 128 · raw
@xs:List<&2, String> -> @n:Nat -> String
def hms source · line 139 · raw
@+t:String -> Nat
def two_digits source · line 144 · raw
@+t:String -> Bool
1*2DIGIT, the shape of each part of a time and of a day-of-month
def is_hms source · line 151 · raw
@+t:String -> Bool
time = hms-time ( non-digit *OCTET ), hms-time = 1*2DIGIT ":" 1*2DIGIT ":" 1*2DIGIT (RFC 6265 5.1.1). A token is a time only in that shape, so no other token ever reaches the arithmetic.
def time_or source · line 160 · raw
@take:Bool -> @+t:String -> @+old:Nat -> Nat
A field is computed only when its token is that field. These were Bool.picks, which build both arms: hms and digits ran on every token, and hms("Coordinated") (JavaScript's Date.toString ends in "(Coordinated Universal Time)", which cloudflare.com sends as Expires) is about 2.7e15, past Bend's largest Nat (2^48 - 1): the whole process stopped.
def digits_or source · line 167 · raw
@take:Bool -> @+t:String -> @+old:Nat -> Nat
def month_or source · line 174 · raw
@take:Bool -> @+t:String -> @+old:Nat -> Nat
def date_step source · line 181 · raw
@d:D -> @+t:String -> D
def date_fold source · line 195 · raw
@ts:List<&2, String> -> @+d:D -> D
def full_year source · line 202 · raw
@+y:Nat -> Nat
def date_secs source · line 206 · raw
@d:D -> U32
Seconds as U32 (until 2106): a Nat this large is costly to the law checker.
def parse_date source · line 214 · raw
@+s:String -> U32
A cookie-date as seconds since 1970, or 0 when it does not parse (or falls outside 1970-2105).
def domain_match source · line 220 · raw
@+host:String -> @+domain:String -> Bool
host is domain, or ends with "." + domain.
def path_match source · line 226 · raw
@+req:String -> @+cpath:String -> Bool
The cookie path is the request path, or a prefix of it ending at a '/'.
def default_path source · line 231 · raw
@+req:String -> String
The directory of the request path ("/a/b/c" -> "/a/b", "/a" -> "/").
def attr_step source · line 241 · raw
@a:A -> @+part:String -> A
def attrs_fold source · line 256 · raw
@ps:List<&2, String> -> @+a:A -> A
def tail_s source · line 263 · raw
@xs:List<&2, String> -> List<&2, String>
def expiry source · line 272 · raw
@+a:A -> @+now:U32 -> U32
Expiry: Max-Age wins over Expires; Max-Age <= 0 means already expired (1, the earliest time); neither means a session cookie (0).
def build source · line 278 · raw
@ok:Bool -> @+name:String -> @+value:String -> @+a:A -> @+host:String -> @+req_path:String -> @+now:U32 -> Maybe<&2, Cookie>
def a_domain source · line 291 · raw
@a:A -> String
def parse source · line 298 · raw
@+header:String -> @+host:String -> @+req_path:String -> @+now:U32 -> Maybe<&2, Cookie>
A Set-Cookie value received from host for req_path at now; None when
it has no name=value pair or its Domain does not cover the host.
def c_name source · line 309 · raw
@c:Cookie -> String
def c_domain source · line 314 · raw
@c:Cookie -> String
def c_path source · line 319 · raw
@c:Cookie -> String
def c_expires source · line 324 · raw
@c:Cookie -> U32
def same_key source · line 329 · raw
@+a:Cookie -> @+b:Cookie -> Bool
def expired source · line 332 · raw
@+c:Cookie -> @+now:U32 -> Bool
def without source · line 335 · raw
@xs:List<&2, Cookie> -> @+c:Cookie -> List<&2, Cookie>
def store source · line 345 · raw
@+jar:List<&2, Cookie> -> @+c:Cookie -> @+now:U32 -> List<&2, Cookie>
Store a cookie: it replaces the one with the same name, domain and path; an expired one only removes.
def store_m source · line 349 · raw
@m:Maybe<&2, Cookie> -> @+jar:List<&2, Cookie> -> @+now:U32 -> List<&2, Cookie>
def store_all source · line 357 · raw
@hs:List<&2, String> -> @+jar:List<&2, Cookie> -> @+host:String -> @+req_path:String -> @+now:U32 -> List<&2, Cookie>
Every Set-Cookie header of a response.
def sends source · line 364 · raw
@c:Cookie -> @+host:String -> @+req_path:String -> @+https:Bool -> @+now:U32 -> Bool
def insert source · line 372 · raw
@+c:Cookie -> @xs:List<&2, Cookie> -> List<&2, Cookie>
Longer paths first; equal paths keep the jar's (creation) order.
def chosen source · line 379 · raw
@xs:List<&2, Cookie> -> @+host:String -> @+req_path:String -> @+https:Bool -> @+now:U32 -> @+acc:List<&2, Cookie> -> List<&2, Cookie>
def pairs source · line 386 · raw
@xs:List<&2, Cookie> -> List<&2, String>
def is_http_only source · line 396 · raw
@c:Cookie -> Bool
The Cookie header value for a request ("" when no cookie applies).
def blocks source · line 404 · raw
@+c:Cookie -> @xs:List<&2, Cookie> -> Bool
A cookie a script stores (document.cookie = ...): not an HttpOnly one (a script cannot make one), and never over an HttpOnly cookie of the same name, domain and path (RFC 6265 5.3, steps 10 and 11).
def script_store_m source · line 411 · raw
@m:Maybe<&2, Cookie> -> @+jar:List<&2, Cookie> -> @+now:U32 -> List<&2, Cookie>
def script_store_all source · line 418 · raw
@hs:List<&2, String> -> @+jar:List<&2, Cookie> -> @+host:String -> @+req_path:String -> @+now:U32 -> List<&2, Cookie>
def header source · line 425 · raw
@+jar:List<&2, Cookie> -> @+host:String -> @+req_path:String -> @+https:Bool -> @+now:U32 -> String
def tf source · line 430 · raw
@+b:Bool -> String
def line_of source · line 433 · raw
@c:Cookie -> String
def lines source · line 439 · raw
@xs:List<&2, Cookie> -> String
def to_text source · line 446 · raw
@+jar:List<&2, Cookie> -> String
def cookie_of_line source · line 449 · raw
@+l:String -> Maybe<&2, Cookie>
def add_m source · line 459 · raw
@m:Maybe<&2, Cookie> -> @+rest:List<&2, Cookie> -> List<&2, Cookie>
def of_lines source · line 466 · raw
@ls:List<&2, String> -> List<&2, Cookie>
def of_text source · line 474 · raw
@+text:String -> List<&2, Cookie>
A jar from cookies.txt text (comments, blank and malformed lines skipped).