Official packages

Network & web

TLS and Let's Encrypt certificates, HTTP/1.1 and HTTP/2, WebDAV, gRPC, reverse proxy and TCP proxy, libcurl client, Web Push notifications.

Overview

Eight packages to talk to the network, from encryption up to application protocols. tls and net-http are also the lower layers of Mosaic, Amalgame's web framework.

At install time: with amc 0.8.92, amc package add prints facade compile errors for tls and for the packages that depend on it (“Unknown symbol 'Acme'”). The package is still added, and amc build recompiles it: programs build. Cases that need an action are flagged below.

The packages

tls v0.3.6

TLS 1.2 and 1.3, client side and server side, on top of OpenSSL 3. It also gets Let's Encrypt certificates without certbot: built-in ACME client (RFC 8555), http-01 challenge, several domain names per certificate.

  • Install: amc package add tls
  • System library: OpenSSL 3 (development headers: libssl-dev on Debian and Ubuntu)
  • Source code: amalgame-lang/amalgame-tls

net-http v0.29.7

HTTP/1.1 and HTTP/2 client and server, with HTTPS, and a WebSocket server (ws and wss, RFC 6455). Four ways to serve: one connection at a time, one thread per connection, fibers (Linux) or a fixed-size thread pool. It also handles Server-Sent Events and multipart forms.

net-webdav v0.8.1

WebDAV server: shares a folder read-only or read-write, with optional locks. WebDavNas turns it into a small multi-account NAS, with one folder per person and a shared folder. CalDAV and CardDAV sync calendars and contacts.

net-grpc v0.7.0

gRPC server and client over HTTP/2, cleartext (h2c) or TLS. All four call types work: unary, server streaming, client streaming and bidirectional. The messages of a stream are collected, then sent in one block.

Note: with amc 0.8.92, amc package add net-grpc fails: the amalgame.toml file of v0.7.0 is malformed, like those of v0.4.1 to v0.6.0. v0.4.0 installs with amc package add net-grpc@v0.4.0; it works in cleartext (h2c) only, with unary calls and server streaming.

net-proxy v0.2.1

HTTP/1.1 reverse proxy: path-prefix routing, X-Forwarded-For header, HTTPS upstreams, load balancing (weighted round-robin, IP hash, least connections).

Limits: no WebSocket, and responses over 1 MiB are truncated.

Note: with amc 0.8.92, the build fails on “Unknown symbol 'Threading'”: also run amc package add threading.

net-stream v0.1.0

TCP proxy to a fixed destination: it relays bytes without reading them. Idle and connect timeouts, global and per-IP connection caps, clean shutdown on SIGINT or SIGTERM.

Limits: v0.1.0 handles TCP only, listens on IPv4 and targets a single destination.

net-curl v0.1.1

HTTP client on top of libcurl: GET, POST, PUT, DELETE and PATCH, HTTPS, followed redirects, custom headers and timeout.

Note: with amc 0.8.92, amc package add net-curl fails: v0.1.1 still declares 0.1.0 in its manifest. v0.1.0, with identical code, installs with amc package add net-curl@v0.1.0.

net-webpush v0.1.2

Sends Web Push notifications (RFC 8030, 8291 and 8292) to a browser or a PWA, even when closed: aes128gcm encryption and VAPID authentication.

Example: a small HTTP server

An HTTP/1.1 server with a pool of 8 threads (net-http). It compiles with amc 0.8.92 after amc package add net-http. Run it, then open http://localhost:8080/.

namespace Demo

import Amalgame.Net.Http

public class Program {
    public static int Main(List<string> args) {
        let handler = conn => {
            if (H1Conn.Path(conn) == "/") {
                H1Conn.Respond(conn, 200, "text/plain", "Hello\n")
            } else {
                H1Conn.Respond(conn, 404, "text/plain", "Not found\n")
            }
            return 0
        }
        // 8 fixed threads; extra connections wait their turn
        let cfg = HttpServerConfig.Default()
        return Http1.ServePool(8080, cfg, handler, 8)
    }
}

See also

For the web framework itself (the web package), go to the Mosaic page. For a WebSocket client, see net-websocket.

At a glance