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.

28 lignes · 671 octetsBrut · Historique
1/// Who sent a request: the `client` effect, and `behind`, its handler
2/// for a server that may sit behind proxies.
3
4import std/http.{type Request}
5import std/option
6
7/// The address a request came from.
8pub effect client
9{
10 fn address :: req: Request -> String
11}
12
13/// Runs `action`, answering `address` with the peer, or with the
14/// `X-Forwarded-For` client when the peer is one of the `trusted`
15/// proxies; `"unknown"` for a request without a peer.
16pub fn behind ::
17 trusted: List<String>
18 action: fn() -> a / <client | e>
19 -> a / <e>
20{
21 handle
22 {
23 action ()
24 }
25 with
26 { address req -> http.client_address req trusted |> option.unwrap_or "unknown"
27 }
28}