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/httpimport {
"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/application/client",
"ZSeanYves/http/core/body",
"ZSeanYves/http/core/types",
"ZSeanYves/http/runtime/transport",
}
supported_targets = "+native"pub async fn get(uri : @types.Uri, trust_anchors? : Bytes) -> Bytes {
@native_client.with_client(
async fn(client) {
let response = client.send(client.request(Get, uri, @client.Upload::bytes(b"")))
@body.collect(response.body, max_bytes=1024 * 1024).0
},
version=Http11,
tls={ ..@transport.TlsOptions::defaults(), alpn: ["http/1.1"], trust_anchors },
policy=@transport.AllowAllPolicy::new(),
)
}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.