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 Retrieval

Find cookies matching requests. More...

Functions

cookie_match_tcookie_jar_get_cookies_for_url (cookie_jar_t *jar, const char *url, bool include_http_only)
 Get cookies that match a URL.
 
cookie_match_tcookie_jar_get_cookies (cookie_jar_t *jar, const char *domain, const char *path, bool secure_only, bool include_http_only)
 Get cookies matching domain and path.
 
void cookie_match_free (cookie_match_t *matches)
 Free a list of cookie matches.
 
char * cookie_match_to_header (const cookie_match_t *matches)
 Convert cookie matches to HTTP Cookie header.
 

Detailed Description

Find cookies matching requests.

Function Documentation

◆ cookie_jar_get_cookies()

cookie_match_t * cookie_jar_get_cookies ( cookie_jar_t * jar,
const char * domain,
const char * path,
bool secure_only,
bool include_http_only )

Get cookies matching domain and path.

Parameters
jarCookie jar
domainRequest domain
pathRequest path
secure_onlyOnly include cookies that work over HTTPS
include_http_onlyInclude HttpOnly cookies
Returns
Linked list of matching cookies

◆ cookie_jar_get_cookies_for_url()

cookie_match_t * cookie_jar_get_cookies_for_url ( cookie_jar_t * jar,
const char * url,
bool include_http_only )

Get cookies that match a URL.

Parameters
jarCookie jar
urlRequest URL
include_http_onlyInclude HttpOnly cookies
Returns
Linked list of matching cookies (caller must free with cookie_match_free)
"https://example.com/api", true);
char *header = cookie_match_to_header(matches);
if (header) {
printf("Cookie: %s\n", header);
free(header);
}
Cookie match result.
Definition cookie.h:228

◆ cookie_match_free()

void cookie_match_free ( cookie_match_t * matches)

Free a list of cookie matches.

Parameters
matchesCookie match list to free

◆ cookie_match_to_header()

char * cookie_match_to_header ( const cookie_match_t * matches)

Convert cookie matches to HTTP Cookie header.

Parameters
matchesCookie match list
Returns
Cookie header string (caller must free), or NULL if no matches
cookie_match_t *matches = cookie_jar_get_cookies_for_url(jar, url, false);
char *cookie_header = cookie_match_to_header(matches);
if (cookie_header) {
// Add to HTTP request: "Cookie: sessionid=abc123; csrf=xyz789"
free(cookie_header);
}