libfetch 0.0.0
A lightweight asynchronous HTTP/1.1 client library implementing a subset of the WHATWG Fetch API.
Loading...
Searching...
No Matches
Cookie Matching Utilities

Low-level domain and path matching functions. More...

Functions

bool cookie_domain_matches (const char *cookie_domain, const char *request_domain)
 Check if cookie domain matches request domain.
 
bool cookie_path_matches (const char *cookie_path, const char *request_path)
 Check if cookie path matches request path.
 
char * cookie_canonicalize_domain (const char *domain)
 Convert domain to canonical lowercase form.
 
char * cookie_default_path (const char *url)
 Extract default path from URL.
 
bool cookie_is_public_suffix (const char *domain)
 Check if domain is a public suffix.
 

Detailed Description

Low-level domain and path matching functions.

Function Documentation

◆ cookie_canonicalize_domain()

char * cookie_canonicalize_domain ( const char * domain)

Convert domain to canonical lowercase form.

Parameters
domainDomain name
Returns
Canonicalized domain (caller must free), or NULL on error

◆ cookie_default_path()

char * cookie_default_path ( const char * url)

Extract default path from URL.

Parameters
urlRequest URL
Returns
Default path for cookies (caller must free)
char *path = cookie_default_path("https://example.com/api/users/123");
// Returns "/api/users" (removes filename and trailing slash)
free(path);

◆ cookie_domain_matches()

bool cookie_domain_matches ( const char * cookie_domain,
const char * request_domain )

Check if cookie domain matches request domain.

Parameters
cookie_domainCookie's domain attribute
request_domainRequest's domain
Returns
True if domain matches
// These all return true:
cookie_domain_matches("example.com", "example.com"); // exact match
cookie_domain_matches(".example.com", "sub.example.com"); // subdomain match
cookie_domain_matches(".example.com", "example.com"); // parent match

◆ cookie_is_public_suffix()

bool cookie_is_public_suffix ( const char * domain)

Check if domain is a public suffix.

Parameters
domainDomain name
Returns
True if domain is a public suffix (like .com, .co.uk)

Prevents cookies from being set on top-level domains.

◆ cookie_path_matches()

bool cookie_path_matches ( const char * cookie_path,
const char * request_path )

Check if cookie path matches request path.

Parameters
cookie_pathCookie's path attribute
request_pathRequest's path
Returns
True if path matches
// These return true:
cookie_path_matches("/", "/anything"); // root matches all
cookie_path_matches("/api", "/api/users"); // prefix match
cookie_path_matches("/api/", "/api/users"); // prefix with slash
// This returns false:
cookie_path_matches("/api", "/application"); // not a prefix