tobogganSe connecter

louise

The Louise language: compiler, runtime, std, tooling

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

43 lignes · 1099 octetsBrut · Historique
1import std/http.{Settings}
2import std/io
3
4// The body limit of a request target (ADR 0012, Revision 5): the first
5// `large_bodies` prefix that matches the path on whole segments, else
6// `max_body`.
7pub fn main :: -> () / <io>
8{
9 let settings =
10 Settings( ..http.defaults ()
11 , max_body: 16
12 , large_bodies: [("/uploads", 64), ("/files/", 32), ("/uploads/big", 128)]
13 )
14 let limit = fn target { io.println (show (http.body_limit settings target)) }
15 limit "/"
16 //> 16
17 limit "/uploads"
18 //> 64
19 limit "/uploads/a/b"
20 //> 64
21 limit "/uploads?x=1"
22 //> 64
23 // Not a whole segment.
24 limit "/uploadsx"
25 //> 16
26 limit "/uploads-old/a"
27 //> 16
28 // The first match wins, even when a later prefix is longer.
29 limit "/uploads/big"
30 //> 64
31 // A prefix written with its slash: `/files` itself is not below it.
32 limit "/files/a"
33 //> 32
34 limit "/files"
35 //> 16
36 // Matched as written: an escaped spelling gets the default.
37 limit "/upl%6Fads/a"
38 //> 16
39 limit "/notes/uploads"
40 //> 16
41 io.println (show (http.body_limit (http.defaults ()) "/uploads"))
42 //> 1048576
43}