http.forms — Lilush API

←index

← http

Overview

Form body building and parsing utilities: URL encoding, HTML escaping, application/x-www-form-urlencoded and multipart/form-data handling. No networking dependencies.

Functions

NameSignature
url_escapeurl_escape(str) -> encoded
html_unescapehtml_unescape(str) -> decoded
html_escapehtml_escape(str) -> escaped
make_form_datamake_form_data(items) -> content_type, body
parse_argsparse_args(body) -> args
parse_form_dataparse_form_data(boundary, body) -> args

url_escape(str) -> encoded

URL-encode a string for safe use in query parameters

Encodes str using application/x-www-form-urlencoded rules:

html_unescape(str) -> decoded

Decode HTML entities back to their original characters

Handles three entity forms:

Codepoints above 255 are decoded to UTF-8 via std.utf.char.

html_escape(str) -> escaped

Escape angle brackets in a string for safe HTML embedding

Only < and > are replaced (&lt; and &gt;). This is intentionally limited to neutralising tags when embedding user-supplied values inside HTML content or attributes. It is not a general-purpose HTML sanitizer — &, ", and ' are left untouched.

make_form_data(items) -> content_type, body

Build a multipart/form-data body from a list of items

Each item in the list is a table with the following fields:

parse_args(body) -> args

Parse a URL-encoded form body into a key-value table

Parses an application/x-www-form-urlencoded body. + signs in values are restored to spaces before URL-decoding; values are then HTML-escaped via html_escape. Returns an empty table for non-string or empty input. Key-value pairs missing the = separator are silently skipped.

parse_form_data(boundary, body) -> args

Parse a multipart/form-data body into a key-value table

Parses a multipart/form-data body using the given boundary string. Text fields are URL-decoded and HTML-escaped. File uploads are returned as tables with filename, content, and content_type fields.