docs(cookie): add API reference page for cookie.h (issue #272) - #320
Merged
Merged
Conversation
Add docs/api/cookie.md covering cwist_cookie_parse, cwist_cookie_get, cwist_cookie_set, cwist_cookie_delete, cwist_cookie_encode and cwist_cookie_decode, with an example that reads a request cookie and sets a response cookie, and link it from the module list in docs/API.md. The page describes the code as it is in src/net/http/cookie.c. No source or header changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #272
Problem
include/cwist/net/http/cookie.h exposes six public functions and one
options struct for reading the request Cookie header and writing
Set-Cookie response headers. None of them appear in docs/, README.md or
any tutorial, so a user has to read the header and cookie.c to learn
how values are encoded, which attributes are written, and what each
call returns on failure.
Fix
Add docs/api/cookie.md in the same format as docs/api/query.md (header
line, then one section per function with its signature and a
description), and link it from the module list in docs/API.md. The page
covers:
"name1=value1; name2=value2" into a cwist_query_map. Whitespace before
a name and after a name is removed; whitespace at the end of a value
is kept. Each value is URL-decoded. Pairs with no "=", with an empty
name, or whose decoded value does not fit in 4096 bytes are skipped.
A NULL map, or a NULL or empty header, does nothing.
if there is none. The pointer belongs to the map and is valid until
the map is destroyed.
secure and same_site. A NULL path, domain or same_site is left out;
http_only and secure are written only when true; max_age_seconds is
written whenever it is 0 or greater, so a zero-initialised struct
produces "Max-Age=0". same_site is copied as given and is not checked
against "Strict", "Lax" or "None".
"name=; Path=...; Domain=...; Max-Age=...; HttpOnly;
Secure; SameSite=...". The value is encoded with cwist_cookie_encode;
the name and attribute strings are written as given. A NULL value is
sent as an empty value and a NULL opts sends only "name=value". It
returns 0 on success and -1 if res or name is NULL, an allocation
fails, or the header is rejected because it contains a CR or LF.
fixed to "/", so a cookie set with a different path is not matched.
It returns 0 on success and -1 on failure.
are kept and every other byte becomes %XX with upper-case hex digits
(a space becomes %20). It returns a heap string for the caller to
release with cwist_free(), or NULL if the input is NULL or allocation
fails.
lower case hex) becomes the byte it names, "+" becomes a space, and a
"%" not followed by two hex digits is copied unchanged. It returns the
number of bytes written without the terminating NUL, or -1 if an
argument is NULL, the buffer size is 0, or the result does not fit
together with the terminating NUL.
sets a "session_id" cookie with Path, Max-Age, HttpOnly, Secure and
SameSite on the response.
Verification
theme=dark from a Cookie header and produces
"session_id=abc%20123; Path=/; Max-Age=3600; HttpOnly; Secure;
SameSite=Lax".
zero-initialised cwist_cookie_options produces "a=b; Max-Age=0"; a
NULL opts produces "c=d"; a CR or LF in the cookie name makes
cwist_cookie_set return -1; cwist_cookie_decode("abc", out, 4)
returns 3 and cwist_cookie_decode("abc", out, 3) returns -1.
src/net/http/http.c (cwist_http_header_add rejects CR and LF).
Scope
planned work.