httpd/request
read-only accessors for HTTP requests.
Since: H3 (a view over stdlib httpd since tourist-on-stdlib-httpd H2)
request-view-new
(request-view-new [hconn ptr<void>] :)
internal: build the Request view of a stdlib conn.
| hconn | the stdlib httpd conn of the current request |
Request -- the view, or the null handle on allocation failure.
Since: tourist-on-stdlib-httpd H2
request-view-free
(request-view-free [req : Request] :)
internal: release a view from request-view-new.
Since: tourist-on-stdlib-httpd H2
req-method
(req-method [req : Request] :)
HTTP method of a parsed request.
| req | Request handle |
:cstr -- uppercase method string, e.g. "GET", "POST"
(req-method req) ; => "POST"
Since: H3
req-path
(req-path [req : Request] :)
request-target path component (no query string).
| req | Request handle |
:cstr -- path beginning with '/', e.g. "/foo/bar"
(req-path req) ; => "/hello"
Since: H3
req-query
(req-query [req : Request] :)
raw query string after '?', or "" if absent.
| req | Request handle |
:cstr -- e.g. "name=world&id=1", or "" if the target had no '?'
(req-query req) ; => "name=world"
Since: H3
req-body
(req-body [req : Request] :)
request body bytes (NUL-terminated; length = Content-Length).
| req | Request handle |
:cstr -- body content, or "" if the request had no body
(req-body req) ; => "hello world"
Since: H3
req-body-len
(req-body-len [req : Request] :)
length of the request body in bytes.
| req | Request handle |
:int -- the byte count (0 when there was no body)
(req-body-len req) ; => 11
Since: tourist-on-stdlib-httpd H2
req-header
(req-header [req : Request name : cstr] :)
look up a request header by name (case-insensitive).
| req | Request handle | |
| name | header name, e.g. "Content-Type" |
(Result cstr cstr) -- ok(value) if the header is present, err("not found") otherwise. Unwrap with ok-val / err-val.
(let [h (req-header req "Content-Type")]
(when (ok? h) (println (ok-val h))))
Since: H3 (typed as Result in 0.2.0)
request-conn
(request-conn [req : Request] :)
the stdlib httpd conn behind a Request.
| req | Request handle |
(Option ptr<void>) -- some(conn) for a server-built Request, none otherwise.
(let [c (request-conn req)]
(when (some? c) (httpd-req-cookie (unwrap c) "session")))
Since: tourist-on-stdlib-httpd H2
req-remote-addr
(req-remote-addr [req : Request] :)
the IP address of the client that sent the request.
| req | Request handle |
(Option cstr) -- some(address), or none when the Request was not built by the server or the address could not be read. The string lives as long as the request.
(let [a (req-remote-addr req)]
(when (some? a) (println (unwrap a)))) ; prints 127.0.0.1
Since: tourist-on-stdlib-httpd H2