tobogganSe connecter

packages

The Louise packages, each released on its own

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

60 lignes · 1354 octetsBrut · Historique
1/// Requests and responses for the tests: what a browser or htmx sends, and
2/// what came back.
3
4import reply.{type Shell, Notice, Shell}
5import std/bytes
6import std/html.{type Html}
7import std/http.{type Request, type Response, Request}
8import std/list
9import std/option
10
11pub fn get :: path: String -> Request
12{
13 Request("GET", path, [], bytes.empty ())
14}
15
16pub fn post :: path: String body: String -> Request
17{
18 Request( "POST"
19 , path
20 , [("Content-Type", "application/x-www-form-urlencoded")]
21 , bytes.from_string body
22 )
23}
24
25pub fn htmx :: req: Request -> Request
26{
27 with_header req "HX-Request" "true"
28}
29
30pub fn with_header :: req: Request name: String value: String -> Request
31{
32 Request(..req, headers: [(name, value), ..req.headers])
33}
34
35pub fn header :: resp: Response name: String -> String
36{
37 list.find resp.headers fn h { h.0 == name }
38 |> option.map fn h { h.1 }
39 |> option.unwrap_or ""
40}
41
42pub fn text :: resp: Response -> String
43{
44 bytes.to_string_lossy
45 (option.unwrap_or (http.whole_body resp) (bytes.empty ()))
46}
47
48/// A shell that frames a page in `main`, its title as an attribute.
49pub fn shell :: -> Shell
50{
51 Shell( framed
52 , Notice("Not found", <p>nothing here</p>)
53 , Notice("Bad request", <p>unreadable</p>)
54 )
55}
56
57fn framed :: title: String content: Html -> Html
58{
59 <main data-title={title}>{content}</main>
60}