part-content-type
(part-content-type [p : Part] :)
the part's Content-Type ("" when it sent none).
| p | Part |
:cstr -- e.g. "image/png"
(part-content-type f) ; => "image/png"
Since: tourist-on-stdlib-httpd H5
No matching definitions.
typed request helpers on Ctx: cookies, forms, uploads,
Since: tourist-on-stdlib-httpd H5
(req-cookie [ctx : Ctx name : cstr] :)
the value of a cookie the request sent.
| ctx | the request's Ctx | |
| name | cookie name (case-sensitive, RFC 6265) |
(Option cstr) -- some(value), owned by the request, or none.
(let [s (req-cookie ctx "theme")]
(text (if (some? s) (unwrap s) "light")))
Since: tourist-on-stdlib-httpd H5
(set-cookie! [ctx : Ctx opts : CookieOpts] :)
queue a Set-Cookie header for the response.
| ctx | the request's Ctx | |
| opts | CookieOpts | |
| A cookie with an empty name is not a cookie: nothing is queued. |
(set-cookie! ctx (cookie "theme" "dark")) (set-cookie! ctx (cookie-full "sid" id "/" "" 3600 1 1 "Strict"))
Since: tourist-on-stdlib-httpd H5
(form-param [ctx : Ctx key : cstr] :)
a field of a URL-encoded form body.
| ctx | the request's Ctx | |
| key | field name (case-sensitive, as sent) |
(Result cstr cstr) -- ok(value), owned by the request; err when the body is not application/x-www-form-urlencoded or has no such field.
(let [r (form-param ctx "email")]
(if (ok? r) (text (ok-val r)) (status 400 (text (err-val r)))))
Since: tourist-on-stdlib-httpd H5
(Part)
one part of a multipart/form-data body (an uploaded file or a
Since: tourist-on-stdlib-httpd H5
(req-file [ctx : Ctx field : cstr] :)
the multipart/form-data part with a given field name.
| ctx | the request's Ctx | |
| field | the form field name of the part |
(Option Part) -- some(part), or none when there is no such part, the body is not multipart, or the Ctx has no server-built request behind it.
(let [f (req-file ctx "avatar")]
(if (some? f)
(with-body-bytes (resp-ok (part-content-type (unwrap f)) "")
(part-data (unwrap f)) (part-data-len (unwrap f)))
(status 400 (text "no file"))))
Since: tourist-on-stdlib-httpd H5
(part-name [p : Part] :)
the part's form field name.
| p | Part |
:cstr -- the name
(part-name f) ; => "avatar"
Since: tourist-on-stdlib-httpd H5
(part-filename [p : Part] :)
the file name the client sent with the part.
| p | Part |
(Option cstr) -- some(name), or none for a plain field.
(part-filename f) ; => some("me.png")
Since: tourist-on-stdlib-httpd H5
(part-content-type [p : Part] :)
the part's Content-Type ("" when it sent none).
| p | Part |
:cstr -- e.g. "image/png"
(part-content-type f) ; => "image/png"
Since: tourist-on-stdlib-httpd H5
(part-data [p : Part] :)
the part's bytes (may hold NULs; see part-data-len).
| p | Part |
:ptr<void> -- the bytes, valid until the response is sent
(with-body-bytes (resp-ok "image/png" "") (part-data f) (part-data-len f))
Since: tourist-on-stdlib-httpd H5
(part-data-len [p : Part] :)
the part's length in bytes.
| p | Part |
:int -- byte count
(part-data-len f) ; => 5120
Since: tourist-on-stdlib-httpd H5
(req-ip [ctx : Ctx] :)
the client's IP address.
| ctx | the request's Ctx |
(Option cstr) -- some(address), or none when it is unknown or the Ctx has no server-built request behind it.
(let [ip (req-ip ctx)] (text (if (some? ip) (unwrap ip) "?")))
Since: tourist-on-stdlib-httpd H5
(req-proto [ctx : Ctx] :)
"https" or "http".
| ctx | the request's Ctx |
:cstr -- "https" or "http" ("http" without a server-built request)
(req-proto ctx) ; => "https"
Since: tourist-on-stdlib-httpd H5
(req-id [ctx : Ctx] :)
the id mw-request-id gave this request.
| ctx | the request's Ctx |
(Option cstr) -- some(id), or none without mw-request-id in tourist-with's stack.
(let [id (req-id ctx)] (when (some? id) (log-with (unwrap id))))
Since: tourist-on-stdlib-httpd H5
(basic-auth [realm : cstr verify : (fn [cstr cstr])
a use! check for HTTP Basic authentication.
| realm | the realm named in the challenge | |
| verify | (fn [cstr cstr] bool): user, password -> accept? |
(fn [Ctx] (Option Response)) -- a use!-shaped check
(use! (basic-auth "admin"
(fn [u : cstr p : cstr] : bool
(= 1 (cstr-eq-const-time p admin-password)))))
Since: tourist-on-stdlib-httpd H5
(auth-user [ctx : Ctx] :)
the user a basic-auth check accepted for this request.
| ctx | the request's Ctx |
(Option cstr) -- some(user), or none when no basic-auth check ran or it rejected the request.
(text (unwrap (auth-user ctx)))
Since: tourist-on-stdlib-httpd H5
(body-limit [max-bytes : int] :)
a use! check that refuses bodies over `max-bytes`.
| max-bytes | the largest body accepted |
(fn [Ctx] (Option Response)) -- a use!-shaped check
(post! "/comment" (guarded (body-limit 4096) post-comment))
Since: tourist-on-stdlib-httpd H5
(guarded [guard : (fn [Ctx])
run a use!-shaped check in front of one route's handler.
| guard | (fn [Ctx] (Option Response)), e.g. basic-auth / body-limit | |
| handler | the route's (fn [Ctx] Response) |
(fn [Ctx] Response) -- a route handler
(post! "/upload" (guarded (body-limit 1048576) upload))
Since: tourist-on-stdlib-httpd H5
__rq-header-raw__rq-body__rq-body-len__rq-form-body?__rq-null?__rq-ptr-null?__rq-free__rq-empty?__rq-own-opt__part-ptr__auth-split!__auth-realm-value__auth-challenge__auth-check