method BodyReader.readAll
All the rest of the body; ProtocolError above limit bytes.
Example:
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) => {
match req.stream().readAll(5) {
bytes b => Reply.text("ok {b.len()}")
NetError _ => Reply.text("too large", 413)
}
})
scope {
spawn stop.serve(router)
let r = Client.postText("{base}/up", "0123456789")?
print("{r.status} {r.text()?}")
stop.shutdown()
()
}?
}
fn main() io, net, time {
match run() {
NetError _ => print("net error")
DecodeError _ => print("decode error")
Panicked _ => print("panicked")
_ => {}
}
}Вывод
413 too large
pub(api) fn readAll(limit: i64 = 67108864, timeout: Duration? = none) -> bytes | NetError netС версии. 1.0.0-beta
Параметры
| Имя | Тип |
|---|---|
limit | i64 = 67108864 |
timeout | Duration? = none |
Возвращает
bytes
Ошибки
NetError- `ProtocolError` above `limit` bytes, `Timeout`, `Unavailable`.
Эффекты
net
Определено в: std/http/http.oxl:1348