data Http2Handle
A copyable reference to an Http2 connection for other tasks (Http2.handle()): requests with the default settings.
Example:
use std.http { Server, ServerConfig, ServerHandle, Router, Request, Reply, Client, Header, HttpConfig, Response, WebSocket, WsConfig, WsKind, WsMessage, SseWriter, SseStream, SseConfig, SseEvent, BodyWriter, Http2, Http2Handle, ResponseStream, chunks }
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().get("/hi", (req: Request) => Reply.text("hi over {req.version}")).post("/echo", (req: Request) => Reply.bytes(req.body, "text/plain"))
scope {
spawn stop.serve(router)
let c = Http2.connect(base)?
defer c.close()
let h: Http2Handle = c.handle()
let r = h.get("/hi")?
print("{r.status} {h.origin == c.origin}")
stop.shutdown()
()
}?
}
fn main() io, net, time {
match run() {
NetError _ => print("net error")
DecodeError _ => print("decode error")
Panicked _ => print("panicked")
_ => {}
}
}Вывод
200 true
@derive(Copy)
pub(api) data Http2HandleПотокобезопасность. copyable; it lets other tasks use the connection but must not outlive `Http2.close()`.
С версии. 1.0.0-beta
Поля
pub(api) origin: str | The origin ( |
Методы
send | (method: str, path: str, headers: List<Header>, body: bytes) -> Response | NetError netSends a request on the shared HTTP/2 connection; path includes the query. |
get | (path: str, headers: List<Header>) -> Response | NetError netGET path on the shared HTTP/2 connection. |
post | (path: str, body: bytes, headers: List<Header>) -> Response | NetError netPOST path with body on the shared HTTP/2 connection. |
Определено в: std/http/http.oxl:5364