httpd/request
src/httpd/request.tur
read-only accessors for parsed HTTP requests.
Since: H3
defn
req-method
(req-method [req : int] :)
HTTP method of a parsed request.
Parameters
| req | :int Request handle |
Returns
:cstr -- uppercase method string, e.g. "GET", "POST"
Example
(req-method req) ; => "POST"
Since: H3
defn
req-path
(req-path [req : int] :)
request-target path component (no query string).
Parameters
| req | :int Request handle |
Returns
:cstr -- path beginning with '/', e.g. "/foo/bar"
Example
(req-path req) ; => "/hello"
Since: H3
defn
req-query
(req-query [req : int] :)
raw query string after '?', or "" if absent.
Parameters
| req | :int Request handle |
Returns
:cstr -- e.g. "name=world&id=1", or "" if the target had no '?'
Example
(req-query req) ; => "name=world"
Since: H3
defn
req-body
(req-body [req : int] :)
request body bytes (NUL-terminated; length = Content-Length).
Parameters
| req | :int Request handle |
Returns
:cstr -- body content, or "" if the request had no body
Example
(req-body req) ; => "hello world"
Since: H3
defn
req-header
(req-header [req : int name : cstr] :)
look up a request header by name (case-insensitive).
Parameters
| req | :int Request handle | |
| name | header name, e.g. "Content-Type" |
Returns
:int -- result<:cstr>: ok(value) if the header is present, err("not found") otherwise. Unwrap with ok-val / err-val.
Example
(let [h (req-header req "Content-Type")]
(when (ok? h) (println (ok-val h))))
Since: H3