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-devon 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.
- Install:
amc package add net-http - System libraries: OpenSSL and libnghttp2
- Source code: amalgame-lang/amalgame-net-http
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.
- Install:
amc package add net-webdav - Source code: amalgame-lang/amalgame-net-webdav
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.
- Install:
amc package add net-grpc - Source code: amalgame-lang/amalgame-net-grpc
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.
- Install:
amc package add net-proxy - Source code: amalgame-lang/amalgame-net-proxy
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.
- Install:
amc package add net-stream - Source code: amalgame-lang/amalgame-net-stream
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.
- Install:
amc package add net-curl - System library: libcurl (
libcurl4-openssl-devon Debian and Ubuntu) - Source code: amalgame-lang/amalgame-net-curl
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.
- Install:
amc package add net-webpush - Source code: amalgame-lang/amalgame-net-webpush
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
- License: Apache-2.0 for all eight packages
- Versions and installation checked with amc 0.8.92
- Official index: amalgame-lang/packages-index