http.url — Lilush API

←index

← http

Overview

URL parsing, building, relative resolution, and percent-encoding per RFC 3986. Provides parse to decompose a URL into its components, build to reassemble a component table back into a string, absolute to resolve relative URLs against a base, and escape/unescape for percent-encoding and decoding.

Functions

NameSignature
escapeescape(s) -> encoded
unescapeunescape(s) -> decoded
parseparse(url_str) -> parsed, err
buildbuild(parsed) -> url_str
absoluteabsolute(base_url, relative_url) -> resolved

escape(s) -> encoded

Percent-encode a string per RFC 3986

Replaces every byte that is not in the RFC 3986 unreserved set (A-Z a-z 0-9 - . _ ~) with its %XX hex-encoded form. This is not application/x-www-form-urlencoded encoding (spaces become %20, not +).

unescape(s) -> decoded

Percent-decode a string

Replaces every %XX hex-encoded sequence with the corresponding byte. Does not decode + as space — that is application/x-www-form-urlencoded behavior, not generic percent-decoding.

parse(url_str) -> parsed, err

Parse a URL into its component parts per RFC 2396

Decomposes a URL string into a table with the following fields (all nil when absent):

Returns nil, "invalid url" for empty or nil input.

build(parsed) -> url_str

Rebuild a URL string from its parsed components

Accepts a table with the same fields returned by parse() and reassembles them into a URL string. Fields that are nil are omitted. When both host and authority are present, host (plus port, user, password) takes precedence for rebuilding the authority portion. IPv6 hosts are automatically wrapped in brackets.

absolute(base_url, relative_url) -> resolved

Resolve a relative URL against a base URL per RFC 2396 section 5.2

If relative_url has a scheme, it is returned as-is (already absolute). Otherwise, missing components are inherited from base_url following the RFC priority: scheme, then authority, then path (merged via dot-component normalization), then params, then query. Fragment is always from the relative URL. base_url may also be a parsed table.