C Collections

chttpserver · Section 3

chttpsvr_req_path

chttpsvr_req_path - return the URL path of a request

C Collections (libccollections, -lccollections)

#include <ccollections/chttpserver.h>
 
const char *chttpsvr_req_path(const chttpsvr_req *req);

Returns the URL path of the request as a NUL-terminated string,
without the query string.  The string is valid until the handler
call returns.
 
The path always starts with "/".  A request whose target is neither
an origin-form path nor an absolute-form http or https URL gets
400 Bad Request before any middleware runs.  The one exception is
"OPTIONS *", which the server answers directly with no middleware
and no handler; see chttpsvr_start(3).  For an absolute-form target
the path is the path of that URL, and an empty one becomes "/".
 
Percent-encoded sequences are decoded by the path rules of RFC 3986,
so the string is the same path that was matched against the route
patterns.  A middleware that runs for a rejected request (see
chttpsvr_use(3)) can see a path with malformed percent-encoding,
which may be the very reason that no route matched.  Such a path has
no decoded form, and the function returns it in its encoded form,
exactly as it arrived.
 
The decoded path can hold a '/' that arrived as %2F, and "." and
".." segments, which the server neither merges nor removes.  Never
use it as a file name without checking it first.

chttpsvr_req_raw_query(3), chttpsvr_req_param(3)