Streaming HTTP protocol suite for MoonBit with HTTP/1.0, HTTP/1.1, HTTP/2, HTTP/3, QUIC, TLS integration, and policy-driven transports.
moon add ZSeanYves/http@0.8.2import {
"ZSeanYves/http/protocol/http1",
} for "test"test "decode a request" {
let decoder = @http1.RequestDecoder::new()
decoder.feed(b"GET /hello HTTP/1.1\r\nHost: localhost\r\n\r\n").unwrap()
guard decoder.next() is Ok(Some(RequestHead(head))) else {
fail("expected request headers")
}
assert_eq(head.uri.value, "/hello")
assert_true(decoder.next() is Ok(Some(RequestEnd)))
}import {
"ZSeanYves/http/adapter/native/client" @native_client,
"ZSeanYves/http/adapter/native/tls" @native_tls,
"ZSeanYves/http/adapter/native/transport" @native_transport,
"ZSeanYves/http/core/types",
"ZSeanYves/http/runtime/transport",
}pub async fn get(uri : @types.Uri, trust_anchors? : Bytes) -> Bytes {
let client = @native_client.new_http1_client(
@native_transport.NativeResolver::new(),
@transport.AllowAllPolicy::new(),
@native_transport.NativeClock::new(),
@native_tls.NativeTlsProvider::new(),
origin_tls={ ..@transport.TlsOptions::defaults(), alpn: ["http/1.1"], trust_anchors },
).unwrap_or_error()
defer client.close()
let response = client.send({
http_method: Get, uri, version: Http11, headers: @types.HeaderMap::new(), body: b"",
}).unwrap_or_error()
guard response.status == 200 else { fail("unexpected HTTP status") }
response.body
}| Capability | Native | Wasm and JS | Wasm-GC |
|---|---|---|---|
| Protocol codecs and QUIC packet protection | Executed | Executed | Synchronous vectors executed |
| Application and stream services | TCP/UDP, DNS and TLS with four HTTP versions on loopback | Async service execution and host byte-stream callback execution | Async service compilation only |
| HTTP/3 deployment | Authenticated QUIC with OpenSSL 3.5 or later within 3.x | Supply host datagrams and QUIC TLS. Portable packet protection vectors | Same host requirements and synchronous QUIC vectors. Async service compilation only |
Install
Download zipStreaming HTTP protocol suite for MoonBit with HTTP/1.0, HTTP/1.1, HTTP/2, HTTP/3, QUIC, TLS integration, and policy-driven transports.