// Reading a response's body in hand (ADR 0053): a streamed body is // written into memory, chunk by chunk, as the server would send it. import std/bytes import std/http import std/io import std/process.{type proc} import std/random.{type random} import std/time.{type clock} fn text :: resp: http.Response -> String / { bytes.to_string_lossy (http.collect_body resp) } pub fn main :: -> () / { io.println (text (http.text 200 "whole")) let streamed = http.stream "text/html; charset=utf-8" fn w { let _ = http.write_string w "

one

" let _ = http.write_string w "" let _ = http.write_chunk w (bytes.from_string "

two

") () } io.println (text streamed) io.println (text (http.stream "text/plain" fn _ { () })) io.println "end" } //> whole //>

one

two

//> //> end