Resolve Pixi trampoline_configuration/wasm2c.json and Conda/Pixi env prefixes in native/build_native.py, add automatic version-matched runtime download from WebAssembly/wabt into build/wasm2c-rt-<ver>/ when binary-only packages (such as conda-forge wabt) omit wasm-rt.h/wasm-rt-impl.c, search Conda/Pixi prefixes for OpenSSL with rpath, and update README.md.
80 lines
3.9 KiB
Markdown
80 lines
3.9 KiB
Markdown
# curl-wasm
|
|
|
|
A `curl` clone implemented **100% in plain WebAssembly Text format (`curl.wat`)**, targeting the **WASI 0.2 Component Model** (`wasi:cli`, `wasi:io`, `wasi:clocks`, `wasi:filesystem`, `wasi:http`).
|
|
|
|
There is no Rust, C, Go, or JavaScript anywhere in the implementation — `curl.wat` assembles directly into a standalone WASI 0.2 component (`curl.wasm`) with `wasm-tools` and executes HTTP and HTTPS (TLS) transfers via `wasmtime`.
|
|
|
|
## Build & Run
|
|
|
|
Prerequisites:
|
|
- `wasm-tools`
|
|
- `wasmtime` (with WASI 0.2 / `wasi:http` support)
|
|
|
|
```sh
|
|
make build
|
|
./curl-wasm https://example.com
|
|
```
|
|
|
|
Or run `curl.wasm` directly with `wasmtime` (note the `--` so `wasmtime` does not intercept flags like `-O`, `-D`, `-h`, or `-V`):
|
|
|
|
```sh
|
|
wasmtime run -S http --dir=. -- ./curl.wasm -fsSI https://example.com
|
|
```
|
|
|
|
Run the test suite:
|
|
|
|
```sh
|
|
make test
|
|
```
|
|
|
|
## Compile to Native (`wasm2c`)
|
|
|
|
You can also compile `curl.wasm` into a standalone native binary (`./curl-native`, backed by POSIX sockets and OpenSSL) using `wasm2c` via `just`:
|
|
|
|
```sh
|
|
just native
|
|
just run-native -fsSI https://example.com
|
|
just test-native
|
|
```
|
|
|
|
If WABT's `wasm2c` runtime sources (`wasm-rt.h` and `wasm-rt-impl.c`) are not found locally (e.g. Pixi/Conda packages that omit headers), `just native` automatically fetches the version-matched runtime files from `WebAssembly/wabt` into `build/`, or honors `WASM2C_RUNTIME_DIR=/path/to/wabt/wasm2c`.
|
|
|
|
## Supported Options
|
|
|
|
| Option | Description |
|
|
| --- | --- |
|
|
| `-h`, `--help` | Show usage help and exit |
|
|
| `-V`, `--version` | Show version/protocols and exit |
|
|
| `-X`, `--request <method>` | Custom HTTP method (`GET`, `POST`, `PATCH`, `DELETE`, custom verbs) |
|
|
| `-H`, `--header <header>` | Add/override header (`Name: Value`), suppress (`Name:`), or send empty (`Name;`) |
|
|
| `-d`, `--data`, `--data-ascii <data>` | Send request body (default `POST`, `@file` / `@-` strips CR/LF) |
|
|
| `--data-raw <data>` | Send literal request body (`@` not treated as file) |
|
|
| `--data-binary <data>` | Send raw binary body (`@file` / `@-` preserves bytes) |
|
|
| `--data-urlencode <data>` | URL-encode data (`content`, `=content`, `name=content`, `@file`, `name@file`) |
|
|
| `-G`, `--get` | Append `-d` data to URL query string and use `GET` |
|
|
| `-T`, `--upload-file <file>` | Upload local file (or `-` for stdin) via `PUT` |
|
|
| `-i`, `--include` | Include response status line and headers in output |
|
|
| `-I`, `--head` | Fetch headers only (`HEAD` request) |
|
|
| `-L`, `--location` | Follow `301`/`302`/`303`/`307`/`308` redirects |
|
|
| `--max-redirs <num>` | Maximum redirects allowed (default `50`, `-1` unlimited) |
|
|
| `-o`, `--output <file>` | Write body to `<file>` (`-` for stdout, `/dev/null` discard sink) |
|
|
| `-O`, `--remote-name` | Write output to local file named from remote URL path |
|
|
| `-D`, `--dump-header <file>` | Write response headers to `<file>` (or `-` for stdout) |
|
|
| `-s`, `--silent` | Silent mode (suppress error messages) |
|
|
| `-S`, `--show-error` | Show errors even when `-s` is enabled |
|
|
| `-v`, `--verbose` | Print `*` info, `>` request headers, and `<` response headers to stderr |
|
|
| `-f`, `--fail` | Fail silently (exit non-zero, no body/file written) on HTTP status >= 400 |
|
|
| `-u`, `--user <user:pass>` | Send `Authorization: Basic ...` header |
|
|
| `-A`, `--user-agent <str>` | Set custom `User-Agent` |
|
|
| `-e`, `--referer <url>` | Set `Referer` header |
|
|
| `-b`, `--cookie <data>` | Set `Cookie` header |
|
|
| `-r`, `--range <range>` | Set `Range: bytes=<range>` header |
|
|
| `-w`, `--write-out <fmt>` | Print transfer stats template after completion |
|
|
| `--connect-timeout <sec>` | Connection timeout in seconds |
|
|
| `-m`, `--max-time <sec>` | Total transfer timeout in seconds |
|
|
| `--` | End of options |
|
|
|
|
### `--write-out` Variables
|
|
|
|
`%{http_code}`, `%{response_code}`, `%{size_download}`, `%{size_upload}`, `%{time_total}`, `%{url_effective}`, `%{content_type}`, `%{redirect_url}`, `%{num_redirects}`, `%{scheme}`, `%{method}`, `\n`, `\r`, `\t`, `\\`, `%%`.
|