web_request

Exposes request metadata, headers, params, cookies, body data, and uploads.

Target type

Signature

1web_request

Exposes request metadata, headers, params, cookies, body data, and uploads.

web_request constructs or identifies a LaiRu value type. web_request belongs at the request or response boundary. Treat visitor input as untrusted, validate before use, and encode values before writing them into HTML.

Examples

Basic call

1web_request->pathInfo
The example belongs near a request or response boundary; validate visitor input before trusting it.

Read request values in a template

1[2local(name) = string(web_request->param('name', 'visitor'))->encodeHtml3local(agent) = string(web_request->header('User-Agent')->second)->encodeHtml4]5<p>Hello [#name]</p>6<p class="meta">User agent: [#agent]</p>
Use defaults for optional params and encode values before writing them into HTML.

Branch on request method

1[2if(web_request->isPost) => {3    local(title) = string(web_request->postParam('title'))->trim4    #title->size > 0 ? 'received: ' + #title | 'missing title'5else6    'show the form'7}8]
Request helpers are ordinary expressions, so they compose cleanly with conditionals.
Comments
proxy.admin@[domain removed for privacy]

When a site is behind a proxy, keep scheme and client-address handling in one helper so templates do not each guess which forwarded header to trust.

1define request_scheme => web_request->secure ? 'https' | 'http'