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.
Dernier runRéussi#125 · main · 16 min 13 s
0Étoiles
0Forks
40Issues
| 1 | // Reading a response's body in hand (ADR 0053): a streamed body is |
| 2 | // written into memory, chunk by chunk, as the server would send it. |
| 3 | |
| 4 | import std/bytes |
| 5 | import std/http |
| 6 | import std/io |
| 7 | import std/process.{type proc} |
| 8 | import std/random.{type random} |
| 9 | import std/time.{type clock} |
| 10 | |
| 11 | fn text :: resp: http.Response -> String / <io, proc, clock, random, ffi> |
| 12 | { |
| 13 | bytes.to_string_lossy (http.collect_body resp) |
| 14 | } |
| 15 | |
| 16 | pub fn main :: -> () / <io, proc, clock, random, ffi> |
| 17 | { |
| 18 | io.println (text (http.text 200 "whole")) |
| 19 | let streamed = |
| 20 | http.stream |
| 21 | "text/html; charset=utf-8" |
| 22 | fn w |
| 23 | { |
| 24 | let _ = http.write_string w "<p>one</p>" |
| 25 | let _ = http.write_string w "" |
| 26 | let _ = http.write_chunk w (bytes.from_string "<p>two</p>") |
| 27 | () |
| 28 | } |
| 29 | io.println (text streamed) |
| 30 | io.println (text (http.stream "text/plain" fn _ { () })) |
| 31 | io.println "end" |
| 32 | } |
| 33 | //> whole |
| 34 | //> <p>one</p><p>two</p> |
| 35 | //> |
| 36 | //> end |