URLs#
RFC 3986 parsing into pointer and length pairs that point into the original string, and reference resolution.
-
struct lwhttp_url_t#
Components of a URI reference split by
lwhttp_url_parse().All pointers point into the parsed string and are not NUL-terminated; use the matching
_lenfield. Components are not decoded or case-normalised. A pointer is meaningful only when itshas_flag is set (pathis always set but may be empty; without an authorityhostisNULLwith length 0).-
const char *scheme#
Scheme without the
:.
-
const char *authority#
Authority without the leading
//: userinfo, host and port.
-
const char *userinfo#
Userinfo before the last
@of the authority.
-
const char *host#
Host, possibly empty; for an IP literal, the address without the brackets.
-
const char *path#
Path, possibly empty.
-
const char *query#
Query without the
?.
-
const char *fragment#
Fragment without the
#.
-
size_t scheme_len#
Length of
lwhttp_url_t.scheme.
-
size_t authority_len#
Length of
lwhttp_url_t.authority.
-
size_t userinfo_len#
Length of
lwhttp_url_t.userinfo.
-
size_t host_len#
Length of
lwhttp_url_t.host.
-
size_t path_len#
Length of
lwhttp_url_t.path.
-
size_t query_len#
Length of
lwhttp_url_t.query.
-
size_t fragment_len#
Length of
lwhttp_url_t.fragment.
-
uint16_t port#
Port number; valid only when
lwhttp_url_t.has_portis set.
-
bool has_scheme#
A scheme is present (the reference is absolute).
-
bool has_authority#
An authority (
//...) is present.
-
bool has_userinfo#
The authority contains userinfo.
-
bool has_port#
The authority contains a non-empty port (
host:with nothing after the colon does not count).
-
bool has_query#
A query is present, possibly empty.
-
bool has_fragment#
A fragment is present, possibly empty.
-
bool ipv6#
The host was written as a bracketed IP literal (
[...]).
-
const char *scheme#
-
lwhttp_error_t lwhttp_url_parse(const char *s, lwhttp_url_t *url)#
Split a URI reference (absolute URL or relative reference) into its components, following RFC 3986.
Nothing is copied or decoded; the result points into
s, which must outlive it. A reference without//has no authority, so"example.com/"is parsed as a path.- Parameters:
s – NUL-terminated URL.
url – Receives the components.
- Returns:
LWHTTP_OK,LWHTTP_ERR_ARGif an argument isNULL, orLWHTTP_ERR_URLifscontains spaces or control characters, the port is not a number up to 65535, or an IP literal is malformed.
-
lwhttp_error_t lwhttp_url_resolve(const char *base, const char *reference, char *out, size_t size)#
Resolve a reference against a base URL (RFC 3986 section 5), removing dot segments.
The fragment of the result comes from
referenceonly. This is how the client resolves redirectLocationvalues.- Parameters:
base – Absolute base URL (must have a scheme).
reference – Absolute URL or relative reference.
out – Receives the NUL-terminated result.
size – Size of
outincluding the terminator.
- Returns:
LWHTTP_OK,LWHTTP_ERR_ARGif a pointer isNULLorsizeis 0,LWHTTP_ERR_URLif either input failslwhttp_url_parse()orbasehas no scheme, orLWHTTP_ERR_TOO_LARGEif the result does not fitout.