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.
Dernier runRéussi#28 · main · 3 min 34 s
0Étoiles
0Forks
3Issues
| 1 | /// Who sent a request: the `client` effect, and `behind`, its handler |
| 2 | /// for a server that may sit behind proxies. |
| 3 | |
| 4 | import std/http.{type Request} |
| 5 | import std/option |
| 6 | |
| 7 | /// The address a request came from. |
| 8 | pub 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. |
| 16 | pub 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 | } |