OxL Reference

method Request.stream

Reader for the body: the pieces as they arrive when the request is streamed, otherwise the buffered body.

Example:

oxl✓ checked in CI
use std.http { Server, ServerConfig, ServerHandle, Router, Request, Reply, Client, Header, HttpConfig, Response, Middleware, Next, withMiddleware, requireHeader, logRequests, timing, WebSocket, WsConfig, SseWriter, BodyWriter, chunks }

fn body(req: Request) -> str {
  match req.text() {
    str t => t
    DecodeError _ => ""
  }
}

fn run() -> () | NetError | DecodeError | Panicked  net, io, time {
  let srv = Server.bind(ServerConfig{ port: 0, followNode: false })?
  defer srv.close()
  let stop = srv.handle()
  let base = "http://127.0.0.1:{srv.port()}"
  let router = Router.new().post("/up", (req: Request) => {
    let r = req.stream()
    match r.readAll() {
      bytes b => Reply.text("{b.len()}")
      NetError _ => Reply.text("failed", 400)
    }
  })
  scope {
    spawn stop.serve(router)
    print((Client.postText("{base}/up", "abcdef")?).text()?)
    stop.shutdown()
    ()
  }?
}

fn main() io, net, time {
  match run() {
    NetError _ => print("net error")
    DecodeError _ => print("decode error")
    Panicked _ => print("panicked")
    _ => {}
  }
}
Output
6
pub(api) fn stream() -> BodyReader

Since. 1.0.0-beta

Returns

BodyReader

Effects

none declared (pure unless the body says otherwise)

Defined in: std/http/http.oxl:1461

See also