No matching definitions.

tourist/request

src/tourist/request.tur

typed request helpers on Ctx: cookies, forms, uploads,

Since: tourist-on-stdlib-httpd H5

defn

form-param

(form-param [ctx : Ctx key : cstr] :)

a field of a URL-encoded form body.

ctxthe request's Ctx
keyfield 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

defopaque

Part

(Part)

one part of a multipart/form-data body (an uploaded file or a

Since: tourist-on-stdlib-httpd H5

defn

req-file

(req-file [ctx : Ctx field : cstr] :)

the multipart/form-data part with a given field name.

ctxthe request's Ctx
fieldthe 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

defn

part-name

(part-name [p : Part] :)

the part's form field name.

pPart

:cstr -- the name

(part-name f)  ; => "avatar"

Since: tourist-on-stdlib-httpd H5

defn

part-filename

(part-filename [p : Part] :)

the file name the client sent with the part.

pPart

(Option cstr) -- some(name), or none for a plain field.

(part-filename f)  ; => some("me.png")

Since: tourist-on-stdlib-httpd H5

defn

part-content-type

(part-content-type [p : Part] :)

the part's Content-Type ("" when it sent none).

pPart

:cstr -- e.g. "image/png"

(part-content-type f)  ; => "image/png"

Since: tourist-on-stdlib-httpd H5

defn

part-data

(part-data [p : Part] :)

the part's bytes (may hold NULs; see part-data-len).

pPart

: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

defn

part-data-len

(part-data-len [p : Part] :)

the part's length in bytes.

pPart

:int -- byte count

(part-data-len f)  ; => 5120

Since: tourist-on-stdlib-httpd H5

defn

req-ip

(req-ip [ctx : Ctx] :)

the client's IP address.

ctxthe 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

defn

req-proto

(req-proto [ctx : Ctx] :)

"https" or "http".

ctxthe request's Ctx

:cstr -- "https" or "http" ("http" without a server-built request)

(req-proto ctx)  ; => "https"

Since: tourist-on-stdlib-httpd H5

defn

req-id

(req-id [ctx : Ctx] :)

the id mw-request-id gave this request.

ctxthe 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

defn

basic-auth

(basic-auth [realm : cstr verify : (fn [cstr cstr])

a use! check for HTTP Basic authentication.

realmthe 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

defn

auth-user

(auth-user [ctx : Ctx] :)

the user a basic-auth check accepted for this request.

ctxthe 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

defn

body-limit

(body-limit [max-bytes : int] :)

a use! check that refuses bodies over `max-bytes`.

max-bytesthe 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

defn

guarded

(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
handlerthe route's (fn [Ctx] Response)

(fn [Ctx] Response) -- a route handler

(post! "/upload" (guarded (body-limit 1048576) upload))

Since: tourist-on-stdlib-httpd H5

Internal definitions
__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